2009-12-14 73 views
1

我有一個使用gSoap以C++編寫的Web服務。其中一個Web服務的方法是VS 2008 wsdl工具將xsd:positiveInteger轉換爲字符串

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 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文件

但是,當我使用Vis生成Proxy類時UAL 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])); 
} 

的WSDL如下:

<?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中的參數標記爲xsd:positiveInteger?我在這裏做錯了什麼?

謝謝!

+0

如果您可以發佈wsdl以及您用於生成C#代理類,它可能會有所幫助。 – 2009-12-15 12:45:02

回答

0

這可能不是你想看到什麼,但是這可能會幫助:Microsoft

基本上它給了你與每個XSD數據類型相關的淨數據類型。在該頁面上,它將positiveInteger顯示爲一個字符串。所以,長話短說它正在做它應該做的事情。如果你真的想要一個數字數據類型,你可能想要使用一個無符號數據類型來代替正整數,如果你需要它永遠是積極的。否則,請使用適合您的xsd數據類型。因爲它看起來像你有控制Web服務和wsdl在c + +這應該不是太困難。如果這不是你想要做的事情,你可能需要在你的c#客戶端上添加邏輯檢查,以確保你發送了一個數字。由於技術上所有東西都以xml字符串形式出現,所以技術上無關緊要,只要該服務可以正確地序列化您的請求即可。因此對您的消費者對象進行數據檢查。

在附註中,當我需要過去開發服務時,我們總是手工編寫xsd/wsdl契約,而不是讓工具生成它們,所以我們總是知道我們會得到什麼。不知道這是你做了什麼,但你也可以做到這一點。當我們這樣做時,我們使用wsdl工具生成服務器代理和客戶端代理,以便您可以在cpp中生成服務器端,在cs中生成客戶端,然後按照需要填寫內容。

希望可以幫助你。