ASMX Proxy Methods的参数为什么要封装?
Why are the parameters of the ASMX Proxy Methods capsulated?
我正在我的 VS2015 或 VS2017 项目 (Net 4.6.1) 中添加对第三方 ASMX Web 服务的服务引用。
我使用 Visual Studio 中的普通用户界面执行此操作(右键单击 --> 添加新服务引用)。我使用默认设置,似乎一切正常,只是我对生成的 类.
不满意
根据 WSDL,我希望使用如下方法:
ServiceSoapClient ssc = new ServiceSoapClient();
object response = ssc.getEmployees("xxx", "yyy", "zzz");
但我得到的是 类 我必须这样使用:
ServiceSoapClient ssc = new ServiceSoapClient();
getEmployeesResponse response = ssc.getEmployees(
new getEmployeesRequest
{
Body = new getEmployeesRequestBody { Division = "xxx", Username = "yyy", Password = "zzz" }
});
每个方法都需要一个请求参数,它本身有一个主体元素。 Body-Element 具有所有必要的参数。
方法在浏览器中打开时定义如下:
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getEmployees xmlns="xxx">
<division>string</division>
<Username>string</Username>
<Password>string</Password>
</getEmployees>
</soap:Body>
</soap:Envelope>
这是 WSDL 中此方法的信息:
<s:element name="getEmployees">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="division" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Username" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="getEmployeesResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="getEmployeesResult" type="tns:XMLResponse"/>
</s:sequence>
</s:complexType>
</s:element>
<wsdl:operation name="getEmployees">
<wsdl:input message="tns:getEmployeesSoapIn"/>
<wsdl:output message="tns:getEmployeesSoapOut"/>
</wsdl:operation>
<wsdl:operation name="getEmployees">
<soap:operation soapAction="http://xxx/getEmployees" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
为什么我没有得到一个带有三个字符串类型参数的方法?我什至可以在客户端控制这个还是有一个常见的错误?
当我自己提供网络服务或使用其他服务时,我以前从未遇到过这个问题。
找到原因了。在 "Service Reference" 的设置中,您必须激活 "Generate assynchronous operations"。
我正在我的 VS2015 或 VS2017 项目 (Net 4.6.1) 中添加对第三方 ASMX Web 服务的服务引用。
我使用 Visual Studio 中的普通用户界面执行此操作(右键单击 --> 添加新服务引用)。我使用默认设置,似乎一切正常,只是我对生成的 类.
不满意根据 WSDL,我希望使用如下方法:
ServiceSoapClient ssc = new ServiceSoapClient();
object response = ssc.getEmployees("xxx", "yyy", "zzz");
但我得到的是 类 我必须这样使用:
ServiceSoapClient ssc = new ServiceSoapClient();
getEmployeesResponse response = ssc.getEmployees(
new getEmployeesRequest
{
Body = new getEmployeesRequestBody { Division = "xxx", Username = "yyy", Password = "zzz" }
});
每个方法都需要一个请求参数,它本身有一个主体元素。 Body-Element 具有所有必要的参数。
方法在浏览器中打开时定义如下:
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getEmployees xmlns="xxx">
<division>string</division>
<Username>string</Username>
<Password>string</Password>
</getEmployees>
</soap:Body>
</soap:Envelope>
这是 WSDL 中此方法的信息:
<s:element name="getEmployees">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="division" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Username" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="getEmployeesResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="getEmployeesResult" type="tns:XMLResponse"/>
</s:sequence>
</s:complexType>
</s:element>
<wsdl:operation name="getEmployees">
<wsdl:input message="tns:getEmployeesSoapIn"/>
<wsdl:output message="tns:getEmployeesSoapOut"/>
</wsdl:operation>
<wsdl:operation name="getEmployees">
<soap:operation soapAction="http://xxx/getEmployees" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
为什么我没有得到一个带有三个字符串类型参数的方法?我什至可以在客户端控制这个还是有一个常见的错误?
当我自己提供网络服务或使用其他服务时,我以前从未遇到过这个问题。
找到原因了。在 "Service Reference" 的设置中,您必须激活 "Generate assynchronous operations"。