Question : How to consume a webservice (external) in VS2010

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.

 
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
<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>


In visual studio 2005, we succeeded to call the service with the following code:
 
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
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;


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:

 
1:
2:
3:
4:
5:
6:
7:
8:
9:
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);


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

 
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
-----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>


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

Answer : How to consume a webservice (external) in VS2010

The best option would be to place a firewall device capable of monitoring traffic and reporting to you the bandwidth usage. You could use a computer sitting around with 2 NICs and SmoothWall (http://www.smoothwall.org/) for example.
Random Solutions  
 
programming4us programming4us