Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi All

When I call a Java-Based webservice with username+password authentication, I need to add custom SoapHeader class which is like this:
C#
[System.Xml.Serialization.XmlTypeAttribute(Namespace="XXX")]
[System.Xml.Serialization.XmlRootAttribute("Security", Namespace="XXX",IsNullable = false)]
public class CustomSoapHeader : SoapHeader{
    public string username;
    public string password;
}

And I add customeSoapHeader property to the Proxy class also rewrite the proxy constructor method like this:
C#
public CustomeSoapHeader cheader;
public XXXSvc(string username, string password){
    this.url = "~~~~~~~~~~~~~~";
    this.cheader = new CustomeSoapHeader(){username = username, password = password};
}

Then I add tag for each method
C#
[System.Web.Services.Protocols.SoapHeaderAttribute("cheader")]
public int myWebMethod(param1, param2){
    // do something
}

After these steps above I can successfully call the method.

But now I need to call these web methods via a Windows Phone client. How could I pass the authentication??
I add service reference to Windows Phone App then it automatically generate the proxy reference.cs and ServiceReferences.ClientConfig
in the config file it uses basicHttpBinding, and I change the security mode to "TransportWithMessageCredential" like this:
XML
<bindings>
    <basicHttpBinding>
        <binding name="myoWSSoapBinding" maxBufferSize="2147483647"
            maxReceivedMessageSize="2147483647">
            <security mode="TransportWithMessageCredential" />
        </binding>
    </basicHttpBinding>
</bindings>


Then I use ClientCredentials to pass through the authentication like this:

C#
proxy.ClientCredentials.username.username = "myUserName"
proxy.ClientCredentials.username.password = "myPassword"

But can not call the method successfully.
How can I solve this problem??
Many Appreciate and thanks for your kindly help, waiting for your answers ^_^
Posted
Updated 14-Jan-14 20:36pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900