如何让WCF服务于Android的定制邮件头 [英] how to get custom message headers of wcf service in android

查看:288
本文介绍了如何让WCF服务于Android的定制邮件头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用这 - >> 链接 << - 所有code设置自定义邮件标题中WCF,但我无法得到这些报头在android的通知通货膨胀。如果任何人有任何的android experices。如何让这些类型的自定义邮件标头值的机器人。

I am using this ->> link <<- all code for setting custom message headers in wcf but i am unable to get these headers inform ation in android. if anyone have any experices in android. how to get these type of custom message header values in android.

像这样code在C#

public class SimpleCustomHeaderService : ISimpleCustomHeaderService
{
    public string DoWork()
    {
        //Do Work
        //...

        //Capture Headers
        var userName = GetHeader("web-user", "ns");
        var webNodeId = GetHeader("web-node-id", "ns");
        var webSessionId = GetHeader("web-session-id", "ns");

        Debug.WriteLine("User: {0} / Node: {1} / Session: {2}", userName, webNodeId, webSessionId);
        var s = string.Format("HeaderInfo: {0}, {1}, {2}",
            userName,
            webNodeId,
            webSessionId);

        return s;
    }

    private static T GetHeader(string name, string ns)
    {
        return OperationContext.Current.IncomingMessageHeaders.FindHeader(name, ns) > -1
            ? OperationContext.Current.IncomingMessageHeaders.GetHeader(name, ns)
            : default(T);
    }
}

但我在做机器人这样这些设置的头信息,但无法获得。这是需要用于获取标题信息的变化。

But i am doing these setting header information in android like this, but unable to get. What is the change needed for getting header information.

方法1

 private static final String    NAMESPACE   = "http://tempuri.org/";
 Element[] header = new Element[1];
 header[0]=buildAuthHeader();
 envelope.headerOut = header;
 Log.i("header", "" + envelope.headerOut.toString());

    envelope.dotNet = false;
    envelope.bodyOut = request;
    envelope.setOutputSoapObject(request);
    int Timeout = 15 * 1000;
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,1000*60*2);
    Log.i("bodyout", "" + envelope.bodyOut.toString());
    Log.i("REQUEST", "" + request.toString());

    try{
        androidHttpTransport.debug = true;
        androidHttpTransport.call(SOAP_ACTION, envelope);

        SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
        returnString = response.toString();
        Log.i("RESPONSE==", response.toString());


private Element buildAuthHeader() {
        String n_s = "ns";
            String web_user_test="john";
    int node_id=1234554;
    //String gid= UUID.randomUUID().toString();
    //String xmlns_soap1="http://schemas.xmlsoap.org/wsdl/soap/";
    //String Namespace="http://www.w3.org/2005/08/addressing";
    //String xmlns_soap="http://schemas.microsoft.com/2003/10/Serialization/";
    Element h = new Element().createElement(NAMESPACE, "ns");
    Element first = new Element().createElement(NAMESPACE, "web-user");
    first.addChild(Node.TEXT,web_user_test);
    h.addChild(Node.ELEMENT, first);

    Element second = new Element().createElement(NAMESPACE, "web-node-id");
    second.addChild(Node.TEXT, String.valueOf(node_id));
    h.addChild(Node.ELEMENT, second);

    Element third = new Element().createElement(NAMESPACE, "web-session-id");
    third.addChild(Node.TEXT, String.valueOf(UUID.randomUUID()));
    h.addChild(Node.ELEMENT, third);
        return h;
    }

我有输出: 响应== HeaderInfo:0,00000000-0000-0000-0000-000000000000

方法2

我也这样做,可选择设置标题:

I have also doing this alternative setting header:

            U= new User();
    U.setProperty(0, "horrorgoogle");
    U.setProperty(1,node_id);
    U.setProperty(2,UUID.randomUUID().toString());


    headerList.add(new HeaderProperty("web-user", U.getProperty(0).toString()));
    headerList.add(new HeaderProperty("web-node-id", U.getProperty(1).toString()));
    headerList.add(new HeaderProperty("web-session-id", U.getProperty(2).toString()));


   androidHttpTransport.call(SOAP_ACTION, envelope,headerList);

我也得到同样的错误,这两种方法。

I have also get same error both method.

我有输出: 响应== HeaderInfo:0,00000000-0000-0000-0000-000000000000

请你,找出错误是在我的code。我很高兴,如果你真的帮我,这我的大问题。

Would you please, find out where is error on my code. I am very glad , if you really help me for this my big problem.

感谢你这么多的阅读我的问题。

Thank you so much reading my problem.

推荐答案

我不认为你已经正确设置你的头。我没有看到你设置的标题[0]。 也许你要插入此行的code

I don't think that you had set your header correctly. I dont see where you set the header[0]. Maybe you have to insert this line of code

envelope.headerOut = header;

这篇关于如何让WCF服务于Android的定制邮件头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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