wsdl没有序列化信息

时间:2011-08-27 09:16:59

标签: wcf soap wsdl

我正在尝试向Web服务发送请求。 wsdl可以在这里看到

https://amsel.dpwn.net/abholportal/gw/lp/schema/1.0/var3ws.wsdl

直接创建请求

            BookLabelRequest request = new BookLabelRequest();

        RpPartnerType rpt = new RpPartnerTypeClient();
        dhlService.BookLabelResponse response = rpt.BookLabel(new dhlService.BookLabelRequest());

但是当没有可序列化的BookLabelRequest公开时,如何将所需参数传递给它?以及如何在标题中传递用户名/密码?

示例SOAP请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:var="https://amsel.dpwn.net/abholportal/gw/lp/schema/1.0/var3bl">
<soapenv:Header>
    <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <wsse:UsernameToken>
            <wsse:Username>username</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">password</wsse:Password>
        </wsse:UsernameToken>
    </wsse:Security>
</soapenv:Header>
<soapenv:Body>
    <var:BookLabelRequest portalId ="OnlineRetoure" deliveryName="Deutschland_Var3" 
                            shipmentReference="notreturnedonlabel" customerReference="CustomerRef1234567890" 
                            labelFormat="PDF" senderName1="Markus" senderName2="Beck" 
                            senderCareOfName="actualnotinuse" senderContactPhone="" 
                            senderStreet="Buschmühlenstraße" senderStreetNumber="40" 
                            senderBoxNumber="" senderPostalCode="58093" senderCity="Hagen"/>
</soapenv:Body>


wsdl文件不是我的,所以我无法编辑它。有没有其他方法可以导入它。我尝试使用svcutil从xsd创建数据协定,但我收到了错误消息:

输入读自“https://amsel.dpwn.net/abholportal/gw/lp/schema/1.0/ var3bl.xsd“与其他选项不一致

我也尝试将用户名和密码传递给代理

            RpPartnerType test = new RpPartnerTypeClient();
        ((RpPartnerTypeClient)test).ClientCredentials.UserName.UserName = "username";
        ((RpPartnerTypeClient)test).ClientCredentials.UserName.Password = "password";

        dhlService.BookLabelResponse response = test.BookLabel(new dhlService.BookLabelRequest());

但得到错误:身份验证失败:没有给出用户名

绑定安全性是:

                <security mode="Transport">
                    <transport clientCredentialType="None" proxyCredentialType="None"
                        realm="" />
                    <message clientCredentialType="UserName" algorithmSuite="Default" />
                </security>

2 个答案:

答案 0 :(得分:1)

您的WSDL正在从其他路径导入带有序列化信息的XSD:

https://amsel.dpwn.net/abholportal/gw/lp/schema/1.0/var3bl.xsd

但WSDL中的位置应指定完整的此路径。

如果您需要使用UserNameToken个人资料,您必须先为您的客户指定绑定:

<bindings>
  <basicHttpBinding>
    <binding name="secured">
      <security mode="TransportWithMessageCredential">
        <transport clientCredentialType="UserName" />
      </security>
    </binding>
  </basicHttpBinding>
</bindings>

在您的客户端端点中使用此绑定:

<client>
  <endpoint address="..." name="..." contract="..." binding="basicHttpBining" 
            bindingConfiguration="secured" />
</client>

配置完客户端后,您需要创建服务和设置凭据的代理“

proxy.ClientCredentials.UserName.UserName = ...;
proxy.ClientCredentials.UserName.Password = ...;

答案 1 :(得分:1)

根据Mike Hadlow的博客创建一个HttpWebRequest并发送。

http://mikehadlow.blogspot.com/2006/05/making-raw-web-service-calls-with.html

可能是实现这一目标的更好方法,但它确实有效。