Error when trying to generate service reference from wsdl - c#

i got a folder with a WSDL file (and all the xsd files related to it) but i can't seem to generate a web service from it using the "Add service reference" option in VS2013 (also tried in 2008 just to test). I'm using .net 4.0.
i get multiple error such as:
Custom tool error: The global type ('WarningType') has been defined in both
'file:///D:/WSDL/AMA/2011Y/chameleon/AMA_CommonTypes.xsd' and
'file:///D:/WSDL/IATA/2010.1/chameleon/IATA_CommonTypes.xsd'.
They are different at './simpleContent/extension/#base'.
so, i was advised to use "Add Web reference" tool.
this works for some reason. i get no errors now.
But, the problem is that i found out that a web reference do not support WS-Security /WS-Adressing
(someone wrote this as a comment in how to add SOAP Security header) and i MUST specify in the header those elements.
Also, i keep reading not to use a web reference since this is an old technology.
So, does anyone know how to solve the errors I'm getting ?

There are multiple tools that generate service proxy objects. Apart from using Add Service Reference you can use command line tool svcutil.exe which is included as part of the visual studios installation for generating service objects.
Here is how to do this
http://msdn.microsoft.com/en-us/library/ff623148.aspx
This alternative command line approach will help you resolve issue related to WS-Security / WS-Adressing.

Related

Adding a service reference using a WSDL which contains links that 'could not be resolved'

I need to add a service reference using a WSDL supplied by a customer. The WSDL contains references to their WCF web service which I cannot see from my development machine. The reference is resolvable on our acceptance environment but I cannot install Visual Studio there.
I thought the point of the WSDL was that it contained all the information for VS to generate the classes necessary to talk to the WS (even without direct access to the WS).
Have have 2 questions:
Is it possible to add this WSDL to my C# project without visibility to their WS
otherwise
Is it possible to generate the classes from the environment that does have direct access to the WS, without installing VS? Maybe by just installing the svcutil.exe (but I imagine this to0l will also require VS)

Service Reference (VS2013) more than one fault is declared with element name in namespace

I'm attempting to consume a web service created by Oracle Web Logic in Visual Studio 2013. I've added the service reference OK but when I call the service constructor I get the error:
In operation (operationName), more than one fault is declared with element name (elementName) in namespace (namespace URL)
The snippets for this operation from the WSDL is shown in the image below:
This exception is thrown each time I attempt to use the service, and I can't proceed any further.
Is this an issue with the WSDL or is there something I can do as a consumer?
I am not sure what is the exact cause of the problem you are facing.
Can you try to generate the proxy using svcutil and give it the flag to generate using the xml serializer.
svcutil.exe /target:code /dataContractOnly /serializer:XmlSerializer
/importXmlTypes [your xsd file's path]
Here is a thread that talks about a similar problem with proxy generation: http://social.msdn.microsoft.com/Forums/vstudio/en-US/66f8c5c0-0c3e-47de-abd3-ba6e1a228f2d/wcf-proxy-data-class-duplication-bug-generating-client-proxy-for-nonwcf-service?forum=wcf
I have some WSDLs that cause me grief in VS newer then 2008. I get around it by using VS2008 and adding the service references there. Then I can save and migrate the generated code over to my VS2010-13 projects. Unfortunately I have not yet found another solution.

Unable to access ColdFusion webservice from C# class

I have to use a ColdFusion webservice in my project. I have
added the service reference in my project and it was successfully loaded, but
service is not accessible in my web application.
What I have done is let's say I have a url http://www.server/service.cfc?wsdl - I have added the above service reference and given the service reference name as MyServiceReference.
When I am accessing MyServiceReference in my class file it is not accessible.
I had a similar issue this week when consuming a Coldfusion webservice. To solve it I suggest you can:
1. Consume the WS using old 'Add Web Reference' (like .NET 2.0) instead of using 'Add Service Reference'
In my case, the problem was the webservice's methods were generated with return void and they hadn't had parameters, but when I added the service using this technique the proxies were correctly generated. This post has helped me.
2. Try using WSDL.exe from Visual Studio Developer Command Tools to see if there is an error with service description
If there is maybe you will not be able to generate proxies correctly and you should ask developers to correct the service.
The tool I mentioned can be found at 'Start Menu\Programs\Microsoft Visual Studio 2012\Visual Studio Tools\Developer Command Prompt for VS2012' (also for VS2010).
In my case I've seen the following error:
"This web reference does not conform to WS-I Basic Profile v1.1.R2706:
A wsdl:binding in a DESCRIPTION MUST use the value of "literal" for the use attribute in all soapbind:body, soapbind:fault, soapbind:header and soapbind:headerfault elements."

Can't use service reference in ASP.NET project

I successfully added a WCF Service Reference to my ASP.NET project, but I'm not able to use it.
I can't import the service referenece via using MyProject.MyService.
This worked in a standard Windows Form project and I now, that the requested service is working.
Thanks for your help.
Edit:
There occure Warnings during the generation of the service client
I think the "main" warning is the following
Warning 1 Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension:System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Type 'Newtonsoft.Json.Linq.JToken' is a recursive collection data contract which is not supported. Consider modifying the definition of collection 'Newtonsoft.Json.Linq.JToken' to remove references to itself.
This warning comes only at the generation in an ASP.NET project. The generation works in my other projects.
It seems that this is a problem of a class I'm not responsible for. May I have to change the settings for the service reference creation or avoid some imports in the original WCF Service class?
We need some more information in order to troubleshoot this for you. Is the reference being added but you cannot use it?
I would suggest looking at the reference.cs file (under the service reference, you may need to tell solution explorer to show all files - little icon of the folders and files at the top) and seeing what namespace it has been generated with.
I think you're probably just not using the correct namespace to reference the client.
The other possibility: check for any compiler warnings, they might give you a clue as to what is going on.
EDIT: This seems to be an issue encountered by others. Do you have the json.net package installed?
Please see the following for details:
Getting "Recursive collection data contract" when referencing a WCF service with a slightly complex method

Can you use WCF services with Windows Phone 7?

I've only been able to find a couple of people online mentioning this, and it seems to be as simple for them as adding the service reference.
However, when I attempt to add a service reference for my WCF service (which works correctly in a regular console app, so I have ruled the WCF out as the problem) I receive a host of errors.
Warning 5 Custom tool warning: No endpoints compatible with Silverlight 3 were found. The generated client class will not be usable unless endpoint information is provided via the constructor.
Warning 6 Custom tool warning: Exception has been thrown by the target of an invocation.
Warning 2 Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Could not load type 'System.Runtime.Serialization.DataContractSet' from assembly 'System.Runtime.Serialization, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'.
Warning 4 Custom tool warning: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.
Warning 3 Custom tool warning: Cannot import wsdl:binding
Detail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.
Error 7 Custom tool error: Failed to generate code for the service reference 'ServiceReference'. Please check other error and warning messages for details.
I find it strange that the first error mentions Silverlight 3, as I just completely uninstalled and reinstalled all of my development tools to ensure that I was using the latest version of .NET and Silverlight.
These errors look similar to the ones I see if I attempt to create a new Silverlight project and do not check the box "Enable WCF RIA services". I have not been able to find any means to enable that for WP7, if that is indeed the problem.
Any assistance from you scholarly gentlemen (and gentlewomen) would be much appreciated.
I ran into the exact same error, and changed the collection type to System.Collections.Generic.List instead of System.Collections.ObjectModel.ObservableCollections. This was odd since I did not even check the box for "Always generate message contracts".
Hope that helps.
Mmmm, I just changed the service reference config by unticking the "reuse type ...." box and then update worked and it generated the service config file. Not sure if this will help you?
Remember that Silverlight - even for Windows Phone, which uses a specialized version of Silverlight 3 - does NOT work with all WCF Service bindings/endpoints, but instead only supports a subset (which excludes WS-HTTP bindings, for example.) Your simplest bet is to create your WCF service for Silverlight applications using the "Silverlight-enabled WCF Service" template in Visual Studio (under Add/New Item/Silverlight).
This blog entry (http://blogs.msdn.com/b/silverlightws/archive/2009/03/20/what-s-new-with-web-services-in-silverlight-3-beta.aspx) from the Silverlight WCF Team Blog should shed some light on the possibilities. You may want to check out he whole blog (http://blogs.msdn.com/b/silverlightws/), as it has some interesting how-to and gotcha articles.
This problem occurred when you run the Visual Studio with Administrator Privilege. What you can do for a workaround is run the Visual Studio without Administrator Privilege, add the web service reference that will generate the proxy classes and close the solution. Open the project solution again in Visual Studio with Administrator privilege. A bug report already file in Microsoft Connect.
https://connect.microsoft.com/VisualStudio/feedback/details/624984/error-warnings-when-adding-web-reference-on-windows-phone-7-project?wa=wsignin1.0
Yes this is one strange Error. You will be able to return Strings, Integers etc but anything else like ArrayList and so forth you will get this error.
There is nothing wrong with your code, there is just a bug with VS. Microsoft have fixed it (check service packs) but if you are programming for Windows Phone 7, the bug is still there.
You have Delete the Service, Then Bin and Obj Folder. Save and close VS. Then restart the Project, Add the Service Ref (DO NOT DEBUG/RUN the app). Oh Yes DO A BACKUP FIRST. It should be ok. You may have to repeat this process everytime you Update the Service.
This should fix it, if not, you may have to open a new project or if possible recreate the Webservice.
The answer is yes, you can access WCF services from WP7, and like a previous poster noted it only supports WS-HTTP. In the case that you are trying to access a WCF Service for a Silverlight application then there are a few things that you need to do:
Update your Silvleright Toolkit to the latest. Go get it from Codeplex
Add a reference to Microsoft.ServiceModel.DomainServices.Hosting to your silverlight project.
Go to the Web.Config and add the soap endpoint:
<domainServices>
<endpoints>
<add name="Soap"
type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory,
Microsoft.ServiceModel.DomainServices.Hosting"
/>
</endpoints>
</domainServices>
Do not worry about the "system.serviceModel" warning; ignore it
Add the service reference. "But, which uri?" you ask. The address of your service is this one: [namespace of your ria service]-[classname of your ria service].svc where . are replaced with -. So, if I have created my service inside of a Services directory in my SL application and the namespace looks like this:
namespace myApplication.Web.Services
{
[EnableClientAccess()]
public class SuperService ....
then the address would be:
http://localhost[:port]/Services/myApplication-Web-Services-SuperService.svc
Let the tooling do the rest. If you get some funky errors then save and close VS and start again and it all works.
I hope that this is the answer that you are looking for.
The following solved my problem:
I created a new WP7 project added the wcf service.
Then I copied the Service References folder to the directory of my project that gave me this problem and restarted Visual studio and built the application.
You should get namespace errors inside your Reference.cs; just change the namespace to the current project namespace.

Categories