I am developing a webservice and a windows application that talk to each
other. They are using a standard VB class library in the background. I am
having problems understanding why I can't sync my namespaces properly.
Example;
My Windows namespace is MyCompany.MyWin dowsSpace
My Webservice namespace is MyCompany.MyWeb Service
My Class Library namespace is MyCompany.MyLib rary
I am using typed objects to send back and forth to my webservice. In my
webservice code-behind page I Have a function that looks like this...
<System.Web.Ser vices.WebServic e(Namespace:="M yCompany.MyLibr ary")_
<System.Web.Ser vices.WebServic eBinding(Confor msTo:=WsiProfil es.BasicProfile 1_1)_
<ToolboxItem(Fa lse)_
Public Class MyWebService
Inherits System.Web.Serv ices.WebService
<WebMethod()_
Public Function HelloWorld(ByVa l MyString As MyCompany.MyLib rary.String)
As MyCompany.MyLib rary.String
Return MyString
End Function
End Class
I register my web reference with my windows application and it asks for a
name. I give it MyWebService as the name. Then, in my code, I use the
following to access the the item and use the webservice...
Protected Friend oWebService As New MyCompany.MyWin dowsSpace.MyWeb Service
Dim oMyString as new MyCompany.MyLib rary.MyString
oMyString.Value = "Hello"
dim oMyStringResult as new MyCompany.MyLib rary.MyString
oMyStringResult = oWebService.Hel loWorld(oMyStri ng)
When I compile the code from above, I get the following error message.
Value of type 'MyCompany.MyLi brary.MyString' cannot be converted to
'MyCompany.MyWe bService.MyStri ng'. on the actual line that calls HelloWorld.
I found a work-around, but I hate doing it, because everytime I make changes
to the web service, I have to go back to the file mentioned below and make
the changes again. I can select to show all files in my web project, then
navigate under web references to the MyWebService's Reference.map.v b file and
change the following code from...
<System.Web.Ser vices.Protocols .SoapDocumentMe thodAttribute(" MyCompany.Libra ry/HelloWorld",
RequestNamespac e:="MyCompany.L ibrary",
ResponseNamespa ce:="MyCompany. Library",
Use:=System.Web .Services.Descr iption.SoapBind ingUse.Literal,
ParameterStyle: =System.Web.Ser vices.Protocols .SoapParameterS tyle.Wrapped) _
Public Function HellowWorld(ByV al oMyString As MyString) As MyString
Dim results() As Object = Me.Invoke("Hell oWorld", New Object()
{oMyString})
Return CType(results(0 ),MyString)
End Function
to...
<System.Web.Ser vices.Protocols .SoapDocumentMe thodAttribute(" MyCompany.Libra ry/HelloWorld",
RequestNamespac e:="MyCompany.L ibrary",
ResponseNamespa ce:="MyCompany. Library",
Use:=System.Web .Services.Descr iption.SoapBind ingUse.Literal,
ParameterStyle: =System.Web.Ser vices.Protocols .SoapParameterS tyle.Wrapped) _
Public Function HellowWorld(ByV al oMyString As
MyCompany.MyLib rary.MyString) As MyCompany.MyLib rary.MyString
Dim results() As Object = Me.Invoke("Hell oWorld", New Object()
{oMyString})
Return CType(results(0 ),MyCompany.MyL ibrary.MyString )
End Function
It forces my object types and allows me to compile it, because they now
match. Does anyone know how to do this the right way? Thanks for your help.
--
Jon Ebersole
Microsoft Certified Solution Developer