0

My android mobile app communicates with web methods. They require user's authentication so I send username and password inside SOAP header as in this link. I've checked it and it generated correctly

    <v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" 
            xmlns:d="http://www.w3.org/2001/XMLSchema" 
            xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" 
            xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
        <v:Header>
            <n0:AuthHeader xmlns:n0="http://tempuri.org/">
                <n0:user>x</n0:user>
                <n0:pass>y</n0:pass>
            </n0:AuthHeader>
        </v:Header>
        <v:Body>
            <AuthenticationUser xmlns="http://tempuri.org/" id="o0" c:root="1" />
        </v:Body>
</v:Envelope>

But on the server side, the web method AuthenticationUser() receives an empty SOAP.

        [WebMethod]
    [SoapHeader("SoapHeader")]
    public string AuthenticationUser()
    {
        if (SoapHeader == null)
            return "Please provide Username and Password !" ;
        if (string.IsNullOrEmpty(SoapHeader.userName) || string.IsNullOrEmpty(SoapHeader.password))
            return "Please provide Username and Password !!" ;

        //Check is User credentials Valid
        if (!SoapHeader.IsUserCredentialsValid(SoapHeader.userName, SoapHeader.password))
            return "Invalid Username or Password !!!";

        // Create and store the AuthenticatedToken before returning it
        string token = Guid.NewGuid().ToString();
        HttpRuntime.Cache.Add(
            token,
            SoapHeader.userName,
            null,
            System.Web.Caching.Cache.NoAbsoluteExpiration,
            TimeSpan.FromMinutes(30),
            System.Web.Caching.CacheItemPriority.NotRemovable,
            null
            );
        return token;
    }

I get the response from AuthenticationUser() web method in my app

    <?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" 
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
               xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <AuthenticationUserResponse xmlns="http://tempuri.org/">
            <AuthenticationUserResult>
                Please provide Username and Password !
            </AuthenticationUserResult>
        </AuthenticationUserResponse>
    </soap:Body>
</soap:Envelope>

I don't know why did AuthenticationUser() web method receive empty SOAP?? Any help will be much appreciated.

Community
  • 1
  • 1
A.J
  • 333
  • 1
  • 2
  • 15
  • print the response and see what it is there. – HaroldSer Nov 19 '16 at 09:21
  • I did. See the above XML, it returns `Please provide Username and Password ! ` which is returned when the SOAP header is null `if (SoapHeader == null) return "Please provide Username and Password !" ;` – A.J Nov 19 '16 at 09:36

1 Answers1

0

I've found my mistake. I did not pay attention for tags. I was trying to send authHeader with user and pass

<n0:AuthHeader xmlns:n0="http://tempuri.org/">
            <n0:user>x</n0:user>
            <n0:pass>y</n0:pass>
</n0:AuthHeader>

where it must be SecuredTokenWebservice with userName and password

 <SecuredTokenWebservice xmlns="http://tempuri.org/">
            <userName>x</userName>
            <password>y</password>
</SecuredTokenWebservice>
A.J
  • 333
  • 1
  • 2
  • 15