C# VS 2008 wsdl工具将xsd:positiveInteger转换为字符串 我有一个用GSOAP写在C++中的Web服务。Web服务的方法之一是 int HS__TBusinessComponentGetContents( xsd__positiveInteger pSession, xsd__positiveInteger pComponentType, xsd__string pPath, xsd__string pFilter, xsd__string pChangedAfter, xsd__positiveInteger pFlags, xsd__string &rResult);
使用这些typedef:C# VS 2008 wsdl工具将xsd:positiveInteger转换为字符串 我有一个用GSOAP写在C++中的Web服务。Web服务的方法之一是 int HS__TBusinessComponentGetContents( xsd__positiveInteger pSession, xsd__positiveInteger pComponentType, xsd__string pPath, xsd__string pFilter, xsd__string pChangedAfter, xsd__positiveInteger pFlags, xsd__string &rResult);,c#,web-services,wsdl,C#,Web Services,Wsdl,使用这些typedef: typedef double xsd__double; typedef wchar_t *xsd__string; typedef bool xsd__boolean; typedef int xsd__int; typedef unsigned long long xsd__positiveInteger;
typedef double xsd__double;
typedef wchar_t *xsd__string;
typedef bool xsd__boolean;
typedef int xsd__int;
typedef unsigned long long xsd__positiveInteger;
typedef wchar_t *xsd__datetime;
我使用此定义生成一个wsdl文件,其中包含以下(正确)部分:
但是,当我使用Visual Studio 2008 wsdl.exe工具生成一个代理类来创建一个可以从C#使用的类时,上述方法的定义如下:
[System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="urn:tango04-hydra-server", ResponseNamespace="urn:tango04-hydra-server")]
[return: System.Xml.Serialization.SoapElementAttribute("rResult")]
public string TBusinessComponentGetContents([System.Xml.Serialization.SoapElementAttribute(DataType="positiveInteger")] string pSession, [System.Xml.Serialization.SoapElementAttribute(DataType="positiveInteger")] string pComponentType, string pPath, string pFilter, string pChangedAfter, [System.Xml.Serialization.SoapElementAttribute(DataType="positiveInteger")] string pFlags) {
object[] results = this.Invoke("TBusinessComponentGetContents", new object[] {
pSession,
pComponentType,
pPath,
pFilter,
pChangedAfter,
pFlags});
return ((string)(results[0]));
}
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="Publisher"
targetNamespace="http://127.0.0.1:18084/Publisher.wsdl"
xmlns:tns="http://127.0.0.1:18084/Publisher.wsdl"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:HS="urn:tango04-hydra-server"
xmlns:SOAP="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:MIME="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:DIME="http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/"
xmlns:WSDL="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<schema targetNamespace="urn:tango04-hydra-server"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:HS="urn:tango04-hydra-server"
xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="unqualified"
attributeFormDefault="unqualified">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
</schema>
</types>
<message name="SessionOpenRequest">
<part name="vCredentials" type="xsd:string"/>
</message>
<message name="SessionOpenResponse">
<part name="rResult" type="xsd:positiveInteger"/>
</message>
<message name="SessionCloseRequest">
<part name="rSession" type="xsd:positiveInteger"/>
</message>
<message name="SessionCloseResponse">
<part name="rResult" type="xsd:boolean"/>
</message>
<message name="SoapTestRequest">
</message>
<message name="SoapTestResponse">
<part name="rResult" type="xsd:boolean"/>
</message>
<message name="TBusinessComponentGetContentsRequest">
<part name="pSession" type="xsd:positiveInteger"/>
<part name="pComponentType" type="xsd:positiveInteger"/>
<part name="pPath" type="xsd:string"/>
<part name="pFilter" type="xsd:string"/>
<part name="pChangedAfter" type="xsd:string"/>
<part name="pFlags" type="xsd:positiveInteger"/>
</message>
<message name="TBusinessComponentGetContentsResponse">
<part name="rResult" type="xsd:string"/>
</message>
<portType name="PublisherPortType">
<operation name="SessionOpen">
<documentation>Service definition of function HS__SessionOpen</documentation>
<input message="tns:SessionOpenRequest"/>
<output message="tns:SessionOpenResponse"/>
</operation>
<operation name="SessionClose">
<documentation>Service definition of function HS__SessionClose</documentation>
<input message="tns:SessionCloseRequest"/>
<output message="tns:SessionCloseResponse"/>
</operation>
<operation name="SoapTest">
<documentation>Service definition of function HS__SoapTest</documentation>
<input message="tns:SoapTestRequest"/>
<output message="tns:SoapTestResponse"/>
</operation>
<operation name="TBusinessComponentGetContents">
<documentation>Service definition of function HS__TBusinessComponentGetContents</documentation>
<input message="tns:TBusinessComponentGetContentsRequest"/>
<output message="tns:TBusinessComponentGetContentsResponse"/>
</operation>
</portType>
<binding name="Publisher" type="tns:PublisherPortType">
<SOAP:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="SessionOpen">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="SessionClose">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="SoapTest">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="TBusinessComponentGetContents">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="Publisher">
<documentation>Tango/04 Computing Group - Publisher </documentation>
<port name="Publisher" binding="tns:Publisher">
<SOAP:address location="http://127.0.0.1:18084"/>
</port>
</service>
</definitions>
WSDL如下所示:
[System.Web.Services.Protocols.SoapRpcMethodAttribute("", RequestNamespace="urn:tango04-hydra-server", ResponseNamespace="urn:tango04-hydra-server")]
[return: System.Xml.Serialization.SoapElementAttribute("rResult")]
public string TBusinessComponentGetContents([System.Xml.Serialization.SoapElementAttribute(DataType="positiveInteger")] string pSession, [System.Xml.Serialization.SoapElementAttribute(DataType="positiveInteger")] string pComponentType, string pPath, string pFilter, string pChangedAfter, [System.Xml.Serialization.SoapElementAttribute(DataType="positiveInteger")] string pFlags) {
object[] results = this.Invoke("TBusinessComponentGetContents", new object[] {
pSession,
pComponentType,
pPath,
pFilter,
pChangedAfter,
pFlags});
return ((string)(results[0]));
}
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="Publisher"
targetNamespace="http://127.0.0.1:18084/Publisher.wsdl"
xmlns:tns="http://127.0.0.1:18084/Publisher.wsdl"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:HS="urn:tango04-hydra-server"
xmlns:SOAP="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:MIME="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:DIME="http://schemas.xmlsoap.org/ws/2002/04/dime/wsdl/"
xmlns:WSDL="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<schema targetNamespace="urn:tango04-hydra-server"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:HS="urn:tango04-hydra-server"
xmlns="http://www.w3.org/2001/XMLSchema"
elementFormDefault="unqualified"
attributeFormDefault="unqualified">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
</schema>
</types>
<message name="SessionOpenRequest">
<part name="vCredentials" type="xsd:string"/>
</message>
<message name="SessionOpenResponse">
<part name="rResult" type="xsd:positiveInteger"/>
</message>
<message name="SessionCloseRequest">
<part name="rSession" type="xsd:positiveInteger"/>
</message>
<message name="SessionCloseResponse">
<part name="rResult" type="xsd:boolean"/>
</message>
<message name="SoapTestRequest">
</message>
<message name="SoapTestResponse">
<part name="rResult" type="xsd:boolean"/>
</message>
<message name="TBusinessComponentGetContentsRequest">
<part name="pSession" type="xsd:positiveInteger"/>
<part name="pComponentType" type="xsd:positiveInteger"/>
<part name="pPath" type="xsd:string"/>
<part name="pFilter" type="xsd:string"/>
<part name="pChangedAfter" type="xsd:string"/>
<part name="pFlags" type="xsd:positiveInteger"/>
</message>
<message name="TBusinessComponentGetContentsResponse">
<part name="rResult" type="xsd:string"/>
</message>
<portType name="PublisherPortType">
<operation name="SessionOpen">
<documentation>Service definition of function HS__SessionOpen</documentation>
<input message="tns:SessionOpenRequest"/>
<output message="tns:SessionOpenResponse"/>
</operation>
<operation name="SessionClose">
<documentation>Service definition of function HS__SessionClose</documentation>
<input message="tns:SessionCloseRequest"/>
<output message="tns:SessionCloseResponse"/>
</operation>
<operation name="SoapTest">
<documentation>Service definition of function HS__SoapTest</documentation>
<input message="tns:SoapTestRequest"/>
<output message="tns:SoapTestResponse"/>
</operation>
<operation name="TBusinessComponentGetContents">
<documentation>Service definition of function HS__TBusinessComponentGetContents</documentation>
<input message="tns:TBusinessComponentGetContentsRequest"/>
<output message="tns:TBusinessComponentGetContentsResponse"/>
</operation>
</portType>
<binding name="Publisher" type="tns:PublisherPortType">
<SOAP:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="SessionOpen">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="SessionClose">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="SoapTest">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
<operation name="TBusinessComponentGetContents">
<SOAP:operation style="rpc" soapAction=""/>
<input>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</input>
<output>
<SOAP:body use="encoded" namespace="urn:tango04-hydra-server" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</output>
</operation>
</binding>
<service name="Publisher">
<documentation>Tango/04 Computing Group - Publisher </documentation>
<port name="Publisher" binding="tns:Publisher">
<SOAP:address location="http://127.0.0.1:18084"/>
</port>
</service>
</definitions>
函数HS_uusessionopen的服务定义
函数HS\uu SessionClose的服务定义
函数HS\uu SoapTest的服务定义
函数HS_uut业务组件getcontents的服务定义
Tango/04计算组-发布者
我的问题是:为什么会发生这种情况?对于wsdl中标记为xsd:positiveInteger的参数,参数不应该是整数或长值而不是字符串吗?我做错了什么
谢谢 这可能不是您希望看到的,但这可能会有所帮助: 基本上,它提供的是与每个xsd数据类型关联的.Net数据类型。在该页面上,它以字符串形式显示positiveInteger。长话短说,它正在做它应该做的事情。如果您真的想要一个数字数据类型,您可能需要考虑使用无符号数据类型而不是正整数,如果您需要它总是正的话。否则,只需使用适合您的xsd数据类型即可。因为它看起来像是在C++中控制Web服务和WSDL,这不应该太困难。如果您不想这样做,您可能需要在c#client上添加逻辑检查,以确保您正在发送一个号码。由于从技术上讲,所有内容都是作为xml字符串传输的,所以只要服务能够正确地序列化您的请求,从技术上讲,这并不重要。因此,对消费者对象进行数据检查 另一方面,当我过去需要开发服务时,我们总是手工编写xsd/wsdl契约,而不是让工具生成它们,因此我们总是确切地知道我们将得到什么。不确定你是否已经做到了,但你也可以做到。当我们这样做的时候,我们使用wsdl工具来生成服务器代理和客户端代理,这样您就可以在cpp中生成服务器端,在cs中生成客户端,然后按照您需要的方式填充内脏
希望这对您有所帮助。如果您可以发布wsdl,并使用它生成C#proxy类,可能会有所帮助。