Cannot convert source type to target type

In the code for .aspx in one of my test web projects, I am trying to set this variable on the returned object. I have a web service link in my web project and it is fine.

I am accessing one of our web service methods:

CompanyName.CC.DebitResponse debitRespnose = CCService.IssueDebit(...);

      

in .asmx IssueDebit returns type CompanyName.CC.DebitResponse.

But I am getting this error:

"Cannot convert source type MyWebTestProject.CCService.DebitResponse to target type CompanyName.CC.DebitResponse"

      

I mean the variable I'm setting up and the return type defined in the method in my service is exactly the same. So why should he complain?

In my webservice, here's the IssueDebit:

public DebitResponse IssueDebit(...)
{
...
}

      

I know for sure that the DebitResponse in the IssueDebit is of type CompanyName.CC.DebitResponse

UPDATED.

Ok I am very stuck. Here's the actual code (before I just changed the names for privacy purposes). Please do not re-insert the whole thing (or if you are changing the names heavily as this is sensitive)

http://www.elbalazo.net/post/codebehind.txt and http://www.elbalazo.net/post/webservice.txt

this is the real code. Have a look at the IssueDebit in the code.

The web service reference I have in my test web project is called LitleService.

When I look at this service in object explorer, I notice that it has a type in conflict. So why would this type be in my service if I don't have this class even defined in my .asax?

http://www.elbalazo.net/post/webservice_objectexplorer.jpg

In another method that I missed in my code, I am getting an ambiguous parameter reference here:

    private void SetIssueDebitResults(ServiceAuthResponse response)
    {
        //not implemented
    }

Ambiguous Reference:
xxx.Litle.ServiceAuthResponse
WebServiceTesting.LitleService.ServiceAuthResponse

      

so why would I get the ServiceAuthResponse objet in my Litle service, for example when the actual start and definition of the ServiceAuthResponse class is in xxx.Litle.ServiceAuthResponse ... in a completely different project? I have this assembly referenced in both web projects (both the test project and my web project containing the actual .asmx).

+2


source to share


4 answers


I'm pretty sure your webservice method is intentional or not, returning the wrong type.

Try putting this at the top of your webservice class:

using DebitResponse = CompanyName.CC.DebitResponse;

      



and then changing the method call to something like:

public DebitResponse IssueDebit(variable)
{
  // stuff...
}

      

If you post the method code IssueDebit()

it will help.

+1


source


It seems to be confusing different namespaces ... if the variables are completely identical, then you can tell them apart.



CompanyName.CC.DebitResponse debitRespnose = (CompanyName.CC.DebitResponse)CCService.IssueDebit(...);

      

0


source


Further on from Bobby's reaction, have you tried this?

CompanyName.CC.DebitResponse debitResponse = 
    CCService.IssueDebit(...) as CompanyName.CC.DebitResponse;

      

0


source


As far as I know, the .NET 2.0 web service (asmx) automatically generates the type mapping required to call the method (parameters and return types) in the WSDL.

When you add a web service as a web link to your other project (your site in this case), the proxy classes are automatically generated. These are the ones in the MyWebTestProject.CCService namespace, in your case. I'm not sure what exactly is in the DebitResponse code, but your error message shows what is wrong:

"Unable to convert source type MyWebTestProject.CCService.DebitResponse to target type CompanyName.CC.DebitResponse"

The type returned by the proxy class that invokes the web service for you is not the type CompanyName.CC.DebitResponse that you are using in your web service. This is a class generated from WSDL, namely MyWebTestProject.CCService.DebitResponse. It will contain all the same data as the class you are using in your webservice, but it is a completely different class. On the other hand, there are no methods existing in a class in your web service.

So, just put: you should use:

MyWebTestProject.CCService.DebitResponse debitResponse = CCService.IssueDebit(...);

      

0


source







All Articles