首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >BancBox SOAP API getClient调用使用WCF客户端基础结构失败。

BancBox SOAP API getClient调用使用WCF客户端基础结构失败。
EN

Stack Overflow用户
提问于 2013-02-23 21:59:41
回答 1查看 1.1K关注 0票数 1

如果这个帖子太长,我会提前道歉。但这是我第一次发帖,而我真的已经过了河,穿过树林试图弄明白这一点。

Visual 2012中的Add引用功能生成一个代理,该代理(显然)生成无效的SOAP消息。我怀疑这与序列化或代理类型是如何修饰有关,但我似乎无法弄清楚。帮助是非常感谢的。

细节1.我的环境是Visual 2012,我已经创建了一个.NET 4.5类库,其中包含对https://sandbox-api.bancbox.com/v1/BBXPort?wsdl的服务引用。我试图调用getClient()函数;这里定义了这个函数。(http://www.bancbox.com/api/view/45)

代码如下所示:

代码语言:javascript
复制
public void GetClient()

{
    // create an instance of the service reference proxy class
    var bbx=newBBXClient();
    bbx.ChannelFactory.Endpoint.Behaviors.Remove<System.ServiceModel.Description.ClientCredentials>();
    bbx.ChannelFactory.Endpoint.Behaviors.Add(new CustomCredentials());

    bbx.ClientCredentials.UserName.UserName="MY_USERNAME";
    bbx.ClientCredentials.UserName.Password="MY_PASSWORD";

    var customerId=newid {
            subscriberReferenceId="44XX33YY"
    };

    var request=newgetClientRequest {
            subscriberId=MY_SUBSCRIBER_ID,
            clientId=customerId
    };

    var response=bbx.getClient(request);
}

详细信息2.我通过SoapUI成功地调用了web服务。成功的SoapUI生成的SOAP消息如下所示

代码语言:javascript
复制
<soapenv:Envelope xmlns:sch="schema.bancbox.com" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<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" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <wsse:UsernameToken wsu:Id="UsernameToken-11">
            <wsse:Username>MY_USERNAME</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">MY_PASSWORD</wsse:Password>
            <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">tRLo6AlRKl+/rULiKq6A6g==</wsse:Nonce>
            <wsu:Created>2013-02-22T18:32:02.204Z</wsu:Created>
        </wsse:UsernameToken>
    </wsse:Security>
</soapenv:Header>
<soapenv:Body>
    <sch:getClient>
        <getClientRequest>
            <subscriberId>MY_SUBSCRIBER_ID</subscriberId>
                <clientId>
                    <!--Optional:-->
                    <subscriberReferenceId>44XX33YY</subscriberReferenceId>
                </clientId>
        </getClientRequest>
    </sch:getClient>
</soapenv:Body>
</soapenv:Envelope>

Detail 3. Fiddler的,我失败的SOAP消息如下所示

代码语言:javascript
复制
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPozcAgEH0QhJHloqMBWUf3mAAAAAA5wy3enJkDUGU8IaMUCFyEjzfL+1Uez1HhAvEeFpJ+30ACQAA</VsDebuggerCausalityData>
    <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <o:UsernameToken u:Id="uuid-6e1c9f81-0651-41f7-b659-26b191bf7e13-1" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <o:Username>MY_USERNAME</o:Username>
            <o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">MY_PASSWORD</o:Password>
            <o:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">hGggJkxurSkHQ3MKoeBK6AmEHNs=</o:Nonce>
            <u:Created>2013-02-23T11:24:47.663Z</u:Created>
        </o:UsernameToken>
    </o:Security>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <getClient xmlns="schema.bancbox.com">
        <getClientRequest xmlns="">
            <subscriberId>MY_SUBSCRIBER_ID</subscriberId>
            <clientId>
                <subscriberReferenceId>XX55YY22</subscriberReferenceId>
            </clientId>
        </getClientRequest>
    </getClient>
</s:Body>
</s:Envelope>

上面的SOAP消息在运行GetClient()方法时产生。GetClient引发以下异常。

代码语言:javascript
复制
System.ServiceModel.FaultException
Unmarshalling Error: cvc-elt.4.2: Cannot resolve 'getClientRequest' to a type definition for element 'getClientRequest'.

当我使用SoapUI重播相同的失败消息时,我会得到以下响应:

代码语言:javascript
复制
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
    <soap:Fault>
        <faultcode>soap:Client</faultcode>
        <faultstring>Unmarshalling Error: cvc-elt.4.2: Cannot resolve 'getClientRequest' to a type definition for element 'getClientRequest'. </faultstring>
    </soap:Fault>
</soap:Body>
</soap:Envelope>

细节4.根据我的研究,这表明另一端的服务器是Apache。被我的肥皂要求压住了。所以我开始玩我的SOAP消息,并通过SoapUI提交它。

成功消息和我的失败消息中的第一个明显的距离是以下几行

成功

代码语言:javascript
复制
<sch:getClient>
    <getClientRequest>

失败

代码语言:javascript
复制
<getClient xmlns="schema.bancbox.com">
    <getClientRequest xmlns="">

因此,我做的第一件事是使我的getClientRequest标记与成功的标记相同。

代码语言:javascript
复制
<getClient xmlns="schema.bancbox.com">
    <getClientRequest>

这产生了以下答复。

代码语言:javascript
复制
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
    <soap:Fault>
        <faultcode>soap:Server</faultcode>
        <faultstring>Found element {schema.bancbox.com}getClientRequest but could not find matching RPC/Literal part</faultstring>
    </soap:Fault>
</soap:Body>
</soap:Envelope>

我所做的下一件事是改变分配模式的getClient标记的方式。

在此之前

代码语言:javascript
复制
<getClient xmlns="schema.bancbox.com">

之后

代码语言:javascript
复制
<s:Envelope xmlns:bb="schema.bancbox.com" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
. . .
    <bb:getClient>
        <getClientRequest>
. . .
    </bb:getClient>

得到的SOAP消息看起来是这样的,它是成功的。

代码语言:javascript
复制
<s:Envelope xmlns:bb="schema.bancbox.com" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPozcAgEH0QhJHloqMBWUf3mAAAAAA5wy3enJkDUGU8IaMUCFyEjzfL+1Uez1HhAvEeFpJ+30ACQAA</VsDebuggerCausalityData>
    <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
        <o:UsernameToken u:Id="uuid-6e1c9f81-0651-41f7-b659-26b191bf7e13-1" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <o:Username>MY_USERNAME</o:Username>
            <o:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">MY_PASSWORD</o:Password>
            <o:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">hGggJkxurSkHQ3MKoeBK6AmEHNs=</o:Nonce>
            <u:Created>2013-02-23T11:24:47.663Z</u:Created>
        </o:UsernameToken>
    </o:Security>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <bb:getClient>
        <getClientRequest>
            <subscriberId>MY_SUBSCRIBER_ID</subscriberId>
            <clientId>
                <subscriberReferenceId>XX55YY22</subscriberReferenceId>
            </clientId>
        </getClientRequest>
    </bb:getClient>
</s:Body>
</s:Envelope>

所以百万美元的问题是为什么和如何。

*为什么.NET代理类以它的方式序列化SOAP消息?

*我如何修复它?如何将代理序列化到上面的SOAP消息中?如何强制序列化程序为信封中的消息命名空间定义速记,然后在消息标记中使用速记?

FYI,为了达到这个目的,我不得不克服WCF的一些WSE问题,并最终在Rich博客上实现了该解决方案。我会张贴链接,但显然我没有足够的代表。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-25 16:08:53

据我所知,WCF产生的SOAP消息在语法上是正确的。但是,Java服务对于它们将接受的SOAP消息非常严格。

WCF代理产生的SOAP消息的操作节点中的xml命名空间定义的特定问题设置别名的解决方案涉及实现一个自定义消息检查器,详见此处:Force WCF to create an xml namespace alias in client proxy

这完全解决了我的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15046238

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档