首页 > 解决方案 > 如何在 C# 中更改 wsdl:part 名称?

问题描述

是否有任何方法可以更改 WSDL 中消息部分的名称?

我的 WSDL 中有这个:

<wsdl:message name="myMethodSoapOut">
     <wsdl:part name="myMethodResult" element="s0:myMethodResult"/>
</wsdl:message>

我想将零件名称更改为:

<wsdl:message name="myMethodSoapOut">
     <wsdl:part name="out" element="s0:myMethodResult"/>
</wsdl:message>

标签: c#.netweb-servicessoapwsdl

解决方案


在您的网络方法中:

[WebMethod]
public MyReturnInfo MyMethod(MyInputInfo input)
{
//your code
return yourInfo;
}

可以这样说,输出作为输出参数返回:

[WebMethod]
public void MyMethod(out MyReturnInfo @out, MyInputInfo input)
{
//your code
@out = yourInfo;
}

在参数中使用“in”和“out”,并保持元素名称正确:

[WebMethod]
public void MyMethod( [System.Xml.Serialization.XmlElement("myInfoResponse", Namespace = "the_name_space_of_the_response")]out MyReturnInfo @out,
[System.Xml.Serialization.XmlElement("myInfoRequest", Namespace = "the_name_space_of_the_request")] MyInputInfo @in)
{
var myVar = DoSomething(@in);
//your code
@out = yourInfo;
}

最后,wsdl:

<wsdl:message name="myInfoSoapIn">
     <wsdl:part name="in" element="s0:myInfoRequest"/>
</wsdl:message>
...
<wsdl:message name="myInfoSoapOut">
     <wsdl:part name="out" element="s0:myInfoResponse"/>
</wsdl:message>

感谢 PD ;)


推荐阅读