How to consume a webservice (external) in VS2010

koldstar
koldstar used Ask the Experts™
on
Hi Everyone,

Im trying to consume a webservice in Visual studio 2010, but having trouble getting a response (that is not failing).

Here is some information about the service:

Url/WSDL: .../services/AuthenticationService?wsdl (service running on a local machine atm.)
Which outputs as shown below when inserted in a browser.

 
<wsdl:definitions name="AuthenticationService" targetNamespace="http://xmlns.oracle.com/Primavera/P6/V7/WS/Authentication">
-
<wsdl:types>
-
<xsd:schema elementFormDefault="qualified" targetNamespace="http://xmlns.oracle.com/Primavera/P6/V7/WS/Authentication">
<xsd:import namespace="http://xmlns.oracle.com/Primavera/P6/V7/WS/IntegrationFaultType" schemaLocation="http://192.168.1.30:7001/p6ws/services/AuthenticationService?xsd=IntegrationFault.xsd"/>
-
<xsd:element name="Login">
-
<xsd:complexType>
-
<xsd:sequence>
<xsd:element name="UserName" type="xsd:string"/>
<xsd:element name="Password" nillable="true" type="xsd:string"/>
<xsd:element minOccurs="0" name="DatabaseInstanceId" type="xsd:int"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
-
<xsd:element name="LoginResponse">
-
<xsd:complexType>
-
<xsd:sequence>
<xsd:element minOccurs="0" name="Return" type="xsd:boolean"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Logout"/>
-
<xsd:element name="LogoutResponse">
-
<xsd:complexType>
-
<xsd:sequence>
<xsd:element minOccurs="0" name="Return" type="xsd:boolean"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="ReadDatabaseInstances"/>
-
<xsd:element name="ReadDatabaseInstancesResponse">
-
<xsd:complexType>
-
<xsd:sequence>
-
<xsd:element maxOccurs="unbounded" name="DatabaseInstance">
-
<xsd:complexType>
-
<xsd:sequence>
<xsd:element name="DatabaseInstanceId" type="xsd:int"/>
<xsd:element name="DatabaseEncoding" type="xsd:string"/>
<xsd:element name="DatabaseName" type="xsd:string"/>
<xsd:element name="DatabaseType" type="tns:DatabaseTypeType"/>
<xsd:element name="DatabaseUrl" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="ReadSessionProperties"/>
-
<xsd:element name="ReadSessionPropertiesResponse">
-
<xsd:complexType>
-
<xsd:sequence>
<xsd:element name="IsValid" type="xsd:boolean"/>
<xsd:element name="UserObjectId" type="xsd:int"/>
<xsd:element name="UserName" type="xsd:string"/>
<xsd:element name="DatabaseInstanceId" type="xsd:int"/>
<xsd:element name="DatabaseEncoding" type="xsd:string"/>
<xsd:element name="DatabaseName" type="xsd:string"/>
<xsd:element name="DatabaseType" type="tns:DatabaseTypeType"/>
<xsd:element name="DatabaseUrl" type="xsd:string"/>
<xsd:element name="IgnoreNullComplexFields" type="xsd:boolean"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
-
<xsd:element name="UpdateSessionProperties">
-
<xsd:complexType>
-
<xsd:sequence>
<xsd:element minOccurs="0" name="IgnoreNullComplexFields" type="xsd:boolean"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
-
<xsd:element name="UpdateSessionPropertiesResponse">
-
<xsd:complexType>
-
<xsd:sequence>
<xsd:element minOccurs="0" name="Return" type="xsd:boolean"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
-
<xsd:simpleType name="DatabaseTypeType">
-
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Oracle"/>
<xsd:enumeration value="SQL Server"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
</wsdl:types>
-
<wsdl:message name="IntegrationFault">
<wsdl:part element="intgfault:IntegrationFault" name="fault">
    </wsdl:part>
</wsdl:message>
-
<wsdl:message name="UpdateSessionPropertiesResponse">
<wsdl:part element="tns:UpdateSessionPropertiesResponse" name="result">
    </wsdl:part>
</wsdl:message>
-
<wsdl:message name="UpdateSessionPropertiesRequest">
<wsdl:part element="tns:UpdateSessionProperties" name="params">
    </wsdl:part>
</wsdl:message>
-
<wsdl:message name="ReadSessionPropertiesResponse">
<wsdl:part element="tns:ReadSessionPropertiesResponse" name="result">
    </wsdl:part>
</wsdl:message>
-
<wsdl:message name="LoginRequest">
<wsdl:part element="tns:Login" name="params">
    </wsdl:part>
</wsdl:message>
-
<wsdl:message name="LogoutRequest">
<wsdl:part element="tns:Logout" name="params">
    </wsdl:part>
</wsdl:message>
-
<wsdl:message name="LoginResponse">
<wsdl:part element="tns:LoginResponse" name="result">
    </wsdl:part>
</wsdl:message>
-
<wsdl:message name="ReadSessionPropertiesRequest">
<wsdl:part element="tns:ReadSessionProperties" name="params">
    </wsdl:part>
</wsdl:message>
-
<wsdl:message name="ReadDatabaseInstancesResponse">
<wsdl:part element="tns:ReadDatabaseInstancesResponse" name="result">
    </wsdl:part>
</wsdl:message>
-
<wsdl:message name="ReadDatabaseInstancesRequest">
<wsdl:part element="tns:ReadDatabaseInstances" name="params">
    </wsdl:part>
</wsdl:message>
-
<wsdl:message name="LogoutResponse">
<wsdl:part element="tns:LogoutResponse" name="result">
    </wsdl:part>
</wsdl:message>
-
<wsdl:portType name="AuthenticationServicePortType">
-
<wsdl:operation name="Login">
<wsdl:input message="tns:LoginRequest">
    </wsdl:input>
<wsdl:output message="tns:LoginResponse">
    </wsdl:output>
<wsdl:fault message="tns:IntegrationFault" name="IntegrationFault">
    </wsdl:fault>
</wsdl:operation>
-
<wsdl:operation name="Logout">
<wsdl:input message="tns:LogoutRequest">
    </wsdl:input>
<wsdl:output message="tns:LogoutResponse">
    </wsdl:output>
</wsdl:operation>
-
<wsdl:operation name="ReadDatabaseInstances">
<wsdl:input message="tns:ReadDatabaseInstancesRequest">
    </wsdl:input>
<wsdl:output message="tns:ReadDatabaseInstancesResponse">
    </wsdl:output>
<wsdl:fault message="tns:IntegrationFault" name="IntegrationFault">
    </wsdl:fault>
</wsdl:operation>
-
<wsdl:operation name="ReadSessionProperties">
<wsdl:input message="tns:ReadSessionPropertiesRequest">
    </wsdl:input>
<wsdl:output message="tns:ReadSessionPropertiesResponse">
    </wsdl:output>
<wsdl:fault message="tns:IntegrationFault" name="IntegrationFault">
    </wsdl:fault>
</wsdl:operation>
-
<wsdl:operation name="UpdateSessionProperties">
<wsdl:input message="tns:UpdateSessionPropertiesRequest">
    </wsdl:input>
<wsdl:output message="tns:UpdateSessionPropertiesResponse">
    </wsdl:output>
</wsdl:operation>
</wsdl:portType>
-
<wsdl:binding name="AuthenticationServiceSOAP12Binding" type="tns:AuthenticationServicePortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
-
<wsdl:operation name="Login">
<soap:operation soapAction="urn:Login" style="document"/>
-
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
-
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
-
<wsdl:fault name="IntegrationFault">
<soap:fault name="IntegrationFault" use="literal"/>
</wsdl:fault>
</wsdl:operation>
-
<wsdl:operation name="Logout">
<soap:operation soapAction="urn:Logout" style="document"/>
-
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
-
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
-
<wsdl:operation name="ReadDatabaseInstances">
<soap:operation soapAction="urn:ReadDatabaseInstances" style="document"/>
-
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
-
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
-
<wsdl:fault name="IntegrationFault">
<soap:fault name="IntegrationFault" use="literal"/>
</wsdl:fault>
</wsdl:operation>
-
<wsdl:operation name="ReadSessionProperties">
<soap:operation soapAction="urn:ReadSessionProperties" style="document"/>
-
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
-
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
-
<wsdl:fault name="IntegrationFault">
<soap:fault name="IntegrationFault" use="literal"/>
</wsdl:fault>
</wsdl:operation>
-
<wsdl:operation name="UpdateSessionProperties">
<soap:operation soapAction="urn:UpdateSessionProperties" style="document"/>
-
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
-
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
-
<wsdl:service name="AuthenticationService">
-
<wsdl:port binding="tns:AuthenticationServiceSOAP12Binding" name="AuthenticationServiceSOAP12port_http">
<soap:address location="http://192.168.1.30:7001/p6ws/services/AuthenticationService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

Open in new window


In visual studio 2005, we succeeded to call the service with the following code:
 
AuthenticationService authService = new AuthenticationService();
authService.CookieContainer = new System.Net.CookieContainer();

authService.Url = "http://192.168.1.30:7001/p6ws/services/AuthenticationService";

Login loginObj = new Login();
loginObj.UserName = Settings.Username;
loginObj.Password = Settings.Password;
loginObj.DatabaseInstanceId = 1;
loginObj.DatabaseInstanceIdSpecified = true;
LoginResponse loginReturn = authService.Login(loginObj);
Settings.CookieContainer = authService.CookieContainer;

Open in new window


however, the "service" AuthenticationService is a class in an attached .dll..

And in VS 2010 i only have the reference to the runinng webservice (I have checked that it really is running.)

I tryied connecting with a similar approach as in VS 2005. In VS 2010 i added a Web Reference to the webservice URL: http://192.168.1.30:7001/p6ws/services/AuthenticationService
and called my webservice: PrimeveraAuthenticationService.

And then tried to connect to the service with the following code:

 
PrimeveraAuthenticationService.Login login = new PrimeveraAuthenticationService.Login();
login.UserName = "the_username"; // username;
login.Password = "the_password"; //password;
login.DatabaseInstanceId = 1;
                PrimeveraAuthenticationService.AuthenticationService service = new PrimeveraAuthenticationService.AuthenticationService();
System.Net.CookieContainer cook_container = new System.Net.CookieContainer();
               
PrimeveraAuthenticationService.LoginResponse loginResponse;
loginResponse = service.Login(login);

Open in new window


I've attached some code that catches the SOAP request and response genereated by the above code, here is the soap-code generated:

 
-----SoapRequest at 05-07-2010 15:08:13
<?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>
	<Login xmlns="http://xmlns.oracle.com/Primavera/P6/V7/WS/Authentication">
	<UserName>test</UserName>
	<Password>test</Password>
	<DatabaseInstanceId>1</DatabaseInstanceId></Login>
	</soap:Body>
</soap:Envelope>



-----SoapResponse at 05-07-2010 15:08:13
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body><soap:Fault>

<faultcode xmlns:ns1="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
	ns1:InvalidSecurity</faultcode>
<faultstring>An error was discovered processing the &lt;wsse:Security&gt; header</faultstring></soap:Fault></soap:Body></soap:Envelope>

Open in new window


There should/could be some kind of security build in the webservice (maybe other than the login.username and login.password), so it might be we have to send Tokens along with the service call, but haven't figured out a way of doing that successfully.

Any help is much appreciated
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Hi,

Any particular reason you cannot add a reference to the dll in VS2010? You should be able to new up the same service instance through that class regardless I think.

/Carl.

Author

Commented:
Hi Carl

We found a way to include the dll.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial