2013-06-21 50 views
0

我正在尝试编写一个作为Web服务使用者的Windows桌面应用程序(使用WCF)。创建Web服务的使用者WSDL/SOAP

应用:

  • 发送SOAP消息给英国政府服务器基于传递

  • 的arugments获得一个认证令牌获取从服务器的形式作出答复包含认证令牌的字符串。

我有一个来自英国政府的SOAP消息模板和一个服务的WSDL文件。

我已经试过

  1. 添加使用WSDL文件的服务引用。我收到以下错误:不支持URI格式。
  2. 使用服务的URL添加Web引用。我收到以下错误:请求失败,HTTP状态405:方法不允许。
  3. 使用POST发送SOAP请求。 GetResponse()调用引发了500次外部服务器错误。

注:我使用VS 2005

WSDL:

<?xml version="1.0" encoding="utf-8"?> 
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:conv="http://www.openuri.org/2002/04/soap/conversation/" xmlns:cw="http://www.openuri.org/2002/04/wsdl/conversation/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:jms="http://www.openuri.org/2002/04/wsdl/jms/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:s1="https://tpvs.hmrc.gov.uk/dpsauthentication" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace="https://tpvs.hmrc.gov.uk/dpsauthentication"> 
    <types> 
     <s:schema elementFormDefault="qualified" targetNamespace="https://tpvs.hmrc.gov.uk/dpsauthentication" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns="https://tpvs.hmrc.gov.uk/dpsauthentication"> 
      <s:element name="DPSrequestToken"> 
       <s:complexType> 
        <s:sequence> 
         <s:element name="version" type="s:int"/> 
         <s:element name="vendorID" type="s:string" minOccurs="0"/> 
        </s:sequence> 
       </s:complexType> 
      </s:element> 
      <s:element name="DPSrequestTokenResponse"> 
       <s:complexType> 
        <s:sequence> 
         <s:element name="DPSrequestTokenResult" type="s:string" minOccurs="0"/> 
        </s:sequence> 
       </s:complexType> 
      </s:element> 
     </s:schema> 
    </types> 
    <message name="DPSrequestTokenSoapIn"> 
     <part name="parameters" element="s1:DPSrequestToken"/> 
    </message> 
    <message name="DPSrequestTokenSoapOut"> 
     <part name="parameters" element="s1:DPSrequestTokenResponse"/> 
    </message> 
    <portType name="dpsauthenticationSoap"> 
     <operation name="DPSrequestToken"> 
      <input message="s1:DPSrequestTokenSoapIn"/> 
      <output message="s1:DPSrequestTokenSoapOut"/> 
     </operation> 
    </portType> 
    <binding name="dpsauthenticationSoap" type="s1:dpsauthenticationSoap"> 
     <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 
     <operation name="DPSrequestToken"> 
      <soap:operation soapAction="https://tpvs.hmrc.gov.uk/dpsauthentication/DPSrequestToken" style="document"/> 
      <input> 
       <soap:body use="literal"/> 
      </input> 
      <output> 
       <soap:body use="literal"/> 
      </output> 
     </operation> 
    </binding> 
    <service name="dpsauthentication"> 
     <port name="dpsauthenticationSoap" binding="s1:dpsauthenticationSoap"> 
      <soap:address location="https://dps.ws.hmrc.gov.uk/dpsauthentication/service"/> 
     </port> 
    </service> 
</definitions> 

SOAP:

<!-- v1.1 30/11/2007 --> 
<!-- 24/10/2011 - minor change to remove duplicated text from <Envelope> element. No impact on validation, therefore not re-versioned. --> 
<SOAP-ENV:Envelope 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"> 
    <SOAP-ENV:Header> 
     <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
      <wsse:UsernameToken> 
       <wsse:Username>as advised by SDS team</wsse:Username> 
       <wsse:Password>as advised by SDS team</wsse:Password> 
      </wsse:UsernameToken> 
     </wsse:Security> 
    </SOAP-ENV:Header> 
    <SOAP-ENV:Body> 
     <m:DPSrequestToken xmlns:m="https://tpvs.hmrc.gov.uk/dpsauthentication"> 
      <m:version>1</m:version> 
      <m:vendorID>your 4 digit vendorID</m:vendorID> 
     </m:DPSrequestToken> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 
+0

“这是我第一次写这类型的应用程序,我卡住了。”你在这里发布的这一事实通知我们所有人,你被困住了。但是,为了帮助你,我们需要知道你到底在哪里/为什么。请发布您的代码和任何/所有例外的堆栈跟踪。 – Brian

+0

@布赖恩你可以看到尝试3这里的代码:http://stackoverflow.com/questions/17223771/call-to-getresponse-is-throwing-500-internal-server-error尝试1和2不放出代码。原因在于缺乏对Web服务,SOAP,WSDL,VS2005或文档的理解。堆栈跟踪只与我尝试的第三件事有关,因为前两个是VS工具,而不是正在执行的代码的一部分。 – Zzz

+0

如果您使用VS2005,那么您如何使用服务引用? –

回答

1

如果别人在同样的问题上运行,我是能够解决这个问题通过使用通常在2. C:\Program Files\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\中找到的WSDL.exe程序。

这个程序创建一个Web服务,它可以让你localy调用API的方法,在你的代码的代理类。

在命令行WSDL.EXE被称为是这样的:3

wsdl http://host/web_service/web_service.asmx?WSDL 
+0

它可以使用svcutil.exe吗? WSDL.EXE是一个传统工具。 –