Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I access / consume this Web Service? 1

Status
Not open for further replies.

klgrube

Programmer
May 29, 2002
28
US
Hi!

I hope someone can help! At work, I manage a SQL server. We also have an Oracle box. I have data in a SQL database that needs to be updated to a database in Oracle. Basically, I need to insert 250 records (four fields each) from a table in the SQL table into an already existing table in Oracle. The head of our IT department has provided me with a web service, but I really have no clue how to use it. I'm fairly new to VB.Net, and consuming a Web Service is a new programming task for me.

I've gone through some exercises on creating and consuming web services, but none of them looks quite like the SOAP description and the sample I've pasted below. Certainly, the "Hello World" example isn't qute the same! At this point, in a new VB.Net app, I've added the web reference correctly and I know how to connect to my SQL table and cycle through the rows in that table. I think I'm supposed to be executing something for each row of the SQL table, but I'm not sure what. I'm also not sure what to do about sending the password and username as part of the AuthHeader. Do I do that for each time I call the CreateNote service? I'm just not sure.

My theory is that, in pseudo code, it would look something like:

For each record in the SQL table
Set RecordVariable = Record from table
CreateNote ( RecordVariable("Comment_Type"), _
RecordVariable("Resort_Number"), _
RecordVariable("Account_Number"), _
RecordVariable("NoteText)
)

Next Record

However, I know this isn't even close to the correct syntax. As you can see below, there are two "Headers" I have no clue about putting information into different "headers" or what the code should look like that consumes this service. I know that for those of you experienced with web services, this is pretty easy stuff, so I apologize for being such a newbie at this. Any advice or samples - or even a reference to a similar (VERY similar) sample would be greatly appreciated.

Thanks!
Karen Grube
klgrube@yahoo.com

==========================================================
CreateNote

SOAP
The following is a sample SOAP request and response. The placeholders shown need to be replaced with actual values.

POST /Notes/Notes.asmx HTTP/1.1
Host: marchtest
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi=" xmlns:xsd=" xmlns:soap=" <soap:Header>
<AuthHeader xmlns=" <Username>string</Username>
<Password>string</Password>
</AuthHeader>
</soap:Header>
<soap:Body>
<CreateNote xmlns=" <Comment_Type>int</Comment_Type>
<Resort_Number>int</Resort_Number>
<Account_Number>int</Account_Number>
<Note_Text>string</Note_Text>
</CreateNote>
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi=" xmlns:xsd=" xmlns:soap=" <soap:Body>
<CreateNoteResponse xmlns=" <CreateNoteResult>int</CreateNoteResult>
</CreateNoteResponse>
</soap:Body>
</soap:Envelope>

==========================================================
========= Description ===================================
<?xml version="1.0" encoding="utf-8" ?>
- <definitions xmlns:http=" xmlns:soap=" xmlns:s=" xmlns:s0=" xmlns:soapenc=" xmlns:tm=" xmlns:mime=" targetNamespace=" xmlns="- <types>
- <s:schema elementFormDefault="qualified" targetNamespace="- <s:element name="CreateNote">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="Comment_Type" type="s:int" />
<s:element minOccurs="1" maxOccurs="1" name="Resort_Number" type="s:int" />
<s:element minOccurs="1" maxOccurs="1" name="Account_Number" type="s:int" />
<s:element minOccurs="0" maxOccurs="1" name="Note_Text" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
- <s:element name="CreateNoteResponse">
- <s:complexType>
- <s:sequence>
<s:element minOccurs="1" maxOccurs="1" name="CreateNoteResult" type="s:int" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="AuthHeader" type="s0:AuthHeader" />
- <s:complexType name="AuthHeader">
- <s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Username" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="Password" type="s:string" />
</s:sequence>
</s:complexType>
</s:schema>
</types>
- <message name="CreateNoteSoapIn">
<part name="parameters" element="s0:CreateNote" />
</message>
- <message name="CreateNoteSoapOut">
<part name="parameters" element="s0:CreateNoteResponse" />
</message>
- <message name="CreateNoteAuthHeader">
<part name="AuthHeader" element="s0:AuthHeader" />
</message>
- <portType name="NotesSoap">
- <operation name="CreateNote">
<input message="s0:CreateNoteSoapIn" />
<output message="s0:CreateNoteSoapOut" />
</operation>
</portType>
- <binding name="NotesSoap" type="s0:NotesSoap">
<soap:binding transport=" style="document" />
- <operation name="CreateNote">
<soap:eek:peration soapAction=" style="document" />
- <input>
<soap:body use="literal" />
<soap:header message="s0:CreateNoteAuthHeader" part="AuthHeader" use="literal" />
</input>
- <output>
<soap:body use="literal" />
</output>
</operation>
</binding>
- <service name="Notes">
- <port name="NotesSoap" binding="s0:NotesSoap">
<soap:address location=" />
</port>
</service>
</definitions>
 
Hi!

Just wanted to add a quick note concerning the web service I described above:

What's unusual about this web service is that I'm not getting data FROM the service, I'm sending data TO the service, so it can be updated on the Oracle box. That confuses the heck out of me, since it's not like the samples I've seen. I can't see what's actually happening to the data once it gets to the service. My guess is that the head of IT has written some code within his service to do the actual update to the Oracle table. I know what you're thinking: why not just ask him and get him to help you code the vb.net app. Well, the answer is he's the head of IT and I don't work for him directly, so asking his help would be embarrassing and my boss wouldn't like it very much. Nor can I even really ask for much of a further explanation of what he's doing. I tried once, and got a very terse response when I asked how other (static) fields in the Oracle table were being updated. "I've exposed all the fields I want you to use. If you don't want to use the web service, then don't." What he meant was that NOT using isn't an option and it's up to me to make this work if I can.

Thanks!
Karen
 
It's easier than you think.

1) Set a web-reference to his web service. This will create some objects in your project that serve as proxies to his code.

2) Call these objects within your code just like they were code that you wrote.

So, if he exposed a method called "InsertRecord" that accepts a number of parameters that make up the record (name, address, etc), after setting the reference, you'd do:

InsertRecord(sName, sAddr1, sAddr2)

and you're done. The .NET runtime will take care of the messy networking code, and your IT manager has already done the code to insert the record in the database.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top