在C#中添加一个肥皂头 [英] add a soap header in C#

查看:111
本文介绍了在C#中添加一个肥皂头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Android构建Xamarin.forms应用程序,我们在其中使用第三方Web服务.我已经创建了代理,并且可以看到该服务公开的方法.

I am building an Xamarin.forms App for android where we are consuming third party webservices. I have created the proxy and I can see the methods exposed by the service.

但是我无法访问服务的方法,因为我必须将标头添加到使用密钥的SOAP请求中.

But I cannot access the methods of the service as I have to add header to my SOAP request which takes the key.

代码段:为代理创建了客户端

Code snippet: created client for the proxy

ThirdPartAuthService.AuthService clnt = new ThirdPartAuthService.AuthService();
clnt.getenquiry(XML);

我看不到任何添加标头的选项,以便进行身份验证.请指导我如何向我的请求中添加肥皂标题.

I do not see any option to add header so that authentication happens. Please guide me how to add soap header to my request..

有可能在android应用中,因为他们正在创建添加标头并发送的SOAP对象.

Its possible in android app as they are creating SOAP object appending the header and sending.

示例标头xml请求:

<?xml version="1.0" encoding="utf-8"?>...
    <soapenv:Header><ns1:encKey soapenv:actor="http://schemas.xmlsoap.org/
    soap/actor/next"  xsi:type="soapenc:string" xmlns:ns1=
     xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
    abcde</ns1:encKey></soapenv:Header>..

我需要添加令牌,用户名和密码

I need to add token, username and password

推荐答案

通过在reference.cs中覆盖System.Net.WebRequest来解决此问题

Fixed it by overriding System.Net.WebRequest in reference.cs

protected override System.Net.WebRequest GetWebRequest(Uri uri)
    { 

        HttpWebRequest request;
        request = (HttpWebRequest)base.GetWebRequest(uri);
        NetworkCredential networkCredentials =   Credentials.GetCredential(uri, "Basic");

        //Other credentials  

        return request;

    } 

这篇关于在C#中添加一个肥皂头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆