Hej! Är nog inte detta som är problemet men ska inte: Ja de e nog bara ett skriv fel från min sida, dock som du säger var det inte detta som ställde till det.Webservice och nuSoup?
Jag har satt upp en väldigt enkel webservice enligt följande:
[WebService(Namespace = "http://test.net/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class companyService : System.Web.Services.WebService {
private companyDatabaseHandler dbHandler = new companyDatabaseHandler();
public companyService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
[WebMethod]
public int getIdByGameName(string gameName)
{
try
{
if (gameName != null && gameName.Length > 0)
return dbHandler.getBoardGameGeekGameIdByGaneName(gameName);
throw (new Exception("gameName is not correct."));
}
catch (Exception ex)
{
throw ex;
}
}
}
Genom att köra denna lokalt och därmed få möjlighet att mata in ett namn för ett spel så kan jag se att webservicen fungerar som tänkt.
Tanken är att en PHP lösning ska kommunicera med denna webservice med hjälp av nuSoup med följande kod:
index.php
<?php
if (!isset($_POST['namn']))
{
echo '<form action="" method="post">';
echo 'Spelnamn: <input type="text" name="namn" />';
echo '<input type="submit"/>';
echo '</form>';
}
else
{
require_once('nusoap.php');
$wsdl = "companyService.wsdl";
$client = new soapclient($wsdl, 'wsdl');
$param = array(
'gameName' => $_POST['namn']
);
$result = $client->call('getIdByGameName', $param);
if ($err = $client->getError())
{
echo "The server returned error: $err";
}
else
{
echo "ID för spel med namn {$_POST['namn']} är: $result <br /><br />\n";
}
}
?>
Och WSDL dokumentet ser ut på följande vis(tänk på att denna innehåller en hel del mer än vad som används, detta för att jag klippt bort från koden oven sådant som är orelevant)
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://test.net/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://test.net/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://test.net/">
<s:element name="HelloWorld">
<s:complexType />
</s:element>
<s:element name="HelloWorldResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="HelloWorldResult" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="registerCompany">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="inName" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="inWebUrl" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="inDescription" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="inContactName" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="inContactPhoneNr" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="inContactEmailAdr" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="inPassword" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="registerCompanyResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="registerCompanyResult" type="s:int" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="getCompanyId">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="inName" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="getCompanyIdResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="getCompanyIdResult" type="s:int" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="removeCompany">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="inCompanyId" type="s:int" />
<s:element minOccurs="0" maxOccurs="1" name="inPassword" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="removeCompanyResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="removeCompanyResult" type="s:int" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="updateGame">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="inCompanyId" type="s:int" />
<s:element minOccurs="0" maxOccurs="1" name="inPassword" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="inBoardGameGeekGameId" type="s:int" />
<s:element minOccurs="1" maxOccurs="1" name="inPriceEach" type="s:double" />
<s:element minOccurs="1" maxOccurs="1" name="inShippingPriceSweden" type="s:double" />
<s:element minOccurs="0" maxOccurs="1" name="inDirectLink" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="updateGameResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="updateGameResult" type="s:int" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="removeGame">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="inCompanyId" type="s:int" />
<s:element minOccurs="0" maxOccurs="1" name="inPassword" type="s:string" />
<s:element minOccurs="1" maxOccurs="1" name="inBoardGameGeekGameId" type="s:int" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="removeGameResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="removeGameResult" type="s:int" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="getCompanyGames">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="inCompanyId" type="s:int" />
<s:element minOccurs="0" maxOccurs="1" name="inPassword" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="getCompanyGamesResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="getCompanyGamesResult">
<s:complexType>
<s:sequence>
<s:any minOccurs="0" maxOccurs="unbounded" namespace="http://www.w3.org/2001/XMLSchema" processContents="lax" />
<s:any minOccurs="1" namespace="urn:schemas-microsoft-com:xml-diffgram-v1" processContents="lax" />
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="getIdByGameName">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="gameName" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="getIdByGameNameResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="getIdByGameNameResult" type="s:int" />
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="HelloWorldSoapIn">
<wsdl:part name="parameters" element="tns:HelloWorld" />
</wsdl:message>
<wsdl:message name="HelloWorldSoapOut">
<wsdl:part name="parameters" element="tns:HelloWorldResponse" />
</wsdl:message>
<wsdl:message name="registerCompanySoapIn">
<wsdl:part name="parameters" element="tns:registerCompany" />
</wsdl:message>
<wsdl:message name="registerCompanySoapOut">
<wsdl:part name="parameters" element="tns:registerCompanyResponse" />
</wsdl:message>
<wsdl:message name="getCompanyIdSoapIn">
<wsdl:part name="parameters" element="tns:getCompanyId" />
</wsdl:message>
<wsdl:message name="getCompanyIdSoapOut">
<wsdl:part name="parameters" element="tns:getCompanyIdResponse" />
</wsdl:message>
<wsdl:message name="removeCompanySoapIn">
<wsdl:part name="parameters" element="tns:removeCompany" />
</wsdl:message>
<wsdl:message name="removeCompanySoapOut">
<wsdl:part name="parameters" element="tns:removeCompanyResponse" />
</wsdl:message>
<wsdl:message name="updateGameSoapIn">
<wsdl:part name="parameters" element="tns:updateGame" />
</wsdl:message>
<wsdl:message name="updateGameSoapOut">
<wsdl:part name="parameters" element="tns:updateGameResponse" />
</wsdl:message>
<wsdl:message name="removeGameSoapIn">
<wsdl:part name="parameters" element="tns:removeGame" />
</wsdl:message>
<wsdl:message name="removeGameSoapOut">
<wsdl:part name="parameters" element="tns:removeGameResponse" />
</wsdl:message>
<wsdl:message name="getCompanyGamesSoapIn">
<wsdl:part name="parameters" element="tns:getCompanyGames" />
</wsdl:message>
<wsdl:message name="getCompanyGamesSoapOut">
<wsdl:part name="parameters" element="tns:getCompanyGamesResponse" />
</wsdl:message>
<wsdl:message name="getIdByGameNameSoapIn">
<wsdl:part name="parameters" element="tns:getIdByGameName" />
</wsdl:message>
<wsdl:message name="getIdByGameNameSoapOut">
<wsdl:part name="parameters" element="tns:getIdByGameNameResponse" />
</wsdl:message>
<wsdl:portType name="companyServiceSoap">
<wsdl:operation name="HelloWorld">
<wsdl:input message="tns:HelloWorldSoapIn" />
<wsdl:output message="tns:HelloWorldSoapOut" />
</wsdl:operation>
<wsdl:operation name="registerCompany">
<wsdl:input message="tns:registerCompanySoapIn" />
<wsdl:output message="tns:registerCompanySoapOut" />
</wsdl:operation>
<wsdl:operation name="getCompanyId">
<wsdl:input message="tns:getCompanyIdSoapIn" />
<wsdl:output message="tns:getCompanyIdSoapOut" />
</wsdl:operation>
<wsdl:operation name="removeCompany">
<wsdl:input message="tns:removeCompanySoapIn" />
<wsdl:output message="tns:removeCompanySoapOut" />
</wsdl:operation>
<wsdl:operation name="updateGame">
<wsdl:input message="tns:updateGameSoapIn" />
<wsdl:output message="tns:updateGameSoapOut" />
</wsdl:operation>
<wsdl:operation name="removeGame">
<wsdl:input message="tns:removeGameSoapIn" />
<wsdl:output message="tns:removeGameSoapOut" />
</wsdl:operation>
<wsdl:operation name="getCompanyGames">
<wsdl:input message="tns:getCompanyGamesSoapIn" />
<wsdl:output message="tns:getCompanyGamesSoapOut" />
</wsdl:operation>
<wsdl:operation name="getIdByGameName">
<wsdl:input message="tns:getIdByGameNameSoapIn" />
<wsdl:output message="tns:getIdByGameNameSoapOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="companyServiceSoap" type="tns:companyServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="HelloWorld">
<soap:operation soapAction="http://test.net/HelloWorld" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="registerCompany">
<soap:operation soapAction="http://test.net/registerCompany" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getCompanyId">
<soap:operation soapAction="http://test.net/getCompanyId" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="removeCompany">
<soap:operation soapAction="http://test.net/removeCompany" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="updateGame">
<soap:operation soapAction="http://test.net/updateGame" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="removeGame">
<soap:operation soapAction="http://test.net/removeGame" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getCompanyGames">
<soap:operation soapAction="http://test.net/getCompanyGames" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getIdByGameName">
<soap:operation soapAction="http://test.net/getIdByGameName" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:binding name="companyServiceSoap12" type="tns:companyServiceSoap">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="HelloWorld">
<soap12:operation soapAction="http://test.net/HelloWorld" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="registerCompany">
<soap12:operation soapAction="http://test.net/registerCompany" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getCompanyId">
<soap12:operation soapAction="http://test.net/getCompanyId" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="removeCompany">
<soap12:operation soapAction="http://test.net/removeCompany" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="updateGame">
<soap12:operation soapAction="http://test.net/updateGame" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="removeGame">
<soap12:operation soapAction="http://test.net/removeGame" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getCompanyGames">
<soap12:operation soapAction="http://test.net/getCompanyGames" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getIdByGameName">
<soap12:operation soapAction="http://test.net/getIdByGameName" style="document" />
<wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="companyService">
<wsdl:port name="companyServiceSoap" binding="tns:companyServiceSoap">
<soap:address location="http://localhost:1705/com/company/webservices/companyService.asmx" />
</wsdl:port>
<wsdl:port name="companyServiceSoap12" binding="tns:companyServiceSoap12">
<soap12:address location="http://localhost:1705/com/company/webservices/companyService.asmx" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Denna lösning får kontakt med webservicen men det har visat sig att null kommer in på parametern, min tanke är att det kanske blir något fel med namespacet.
Kanske ni kan se felet?Sv: Webservice och nuSoup?
return dbHandler.getBoardGameGeekGameIdByGaneName(gameName);
vara
return dbHandler.getBoardGameGeekGameIdByGameName(gameName);
I ditt exempel strår det ...ByGaneName, det ska troligtvis vara ...ByGameNemeSv:Webservice och nuSoup?
Istället vat det så att Webservicen genererar alla sina syper som complex types vilket ställer till det lite.
Genom att anropa webmetoderna genom att ange proxyn före så löser man detta problem.