SweLogan
asked on
Web Service AuthenticationHeader VB.net - PHP
Hi, new here at Experts Exchange, I'm about to build an API in VB.NET which is called from a PHP page.
I got HelloWorld() work. But GetData() is not working! Can't see any Error message.
My point of this question is how do I enter information in SoapHeader with "Service1.asmx?WSDL?&UserI D=AdminPas sword=Admi n" And then use this to keep track of user?
I got HelloWorld() work. But GetData() is not working! Can't see any Error message.
My point of this question is how do I enter information in SoapHeader with "Service1.asmx?WSDL?&UserI
========= VB.NET CODE =========
Public Class Service1
Inherits System.Web.Services.WebService
'class that inherits from SoapHeader
Public Class MyHeader
Inherits SoapHeader
Public UserID As String
Public Password As String
End Class
'instance of soap header class
'this will be populated by client and send back
Public objMyHeader As MyHeader
'set soap header details
<WebMethod(), SoapHeader("objMyHeader", direction:=SoapHeaderDirection.InOut)> Public Function GetData() As String
If objMyHeader.UserID = "Admin" And objMyHeader.Password = "Admin" Then
Return "Valid user"
''Call your second method here
Else
Return "Invalid user"
End If
End Function
<WebMethod()> Public Function HelloWorld() As String
Return "Hello World"
End Function
End Class
========= PHP CODE =========
<?php
try {
$serviceUrl = "http://localhost:53719/Service1.asmx";
$client = new SoapClient($serviceUrl . "?WSDL",
array("location" => $serviceUrl .
"?UserID=Admin&Password=Admin"));
$objectresult = $client->GetData();
} catch(SoapFault $soapFault) {
echo "Error: " . $soapFault->faultstring;
}
?>
========= SOAP CODE =========
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<MyHeader xmlns="http://tempuri.org/">
<UserID>string</UserID>
<Password>string</Password>
</MyHeader>
</soap:Header>
<soap:Body>
<GetData xmlns="http://tempuri.org/" />
</soap:Body>
</soap:Envelope>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.