I have a WCF service with 2 endpoints (1 webHttpBinding and 1 basicHttpBinding) that is hosted in IIS. Clients are able to make http requests without a problem. I was able to connect and make calls to the SOAP endpoint via the WCFTestClient, and was able to successfully add the service reference to my client project. The problem is that there is no code generated in the Reference.cs file or the app.config file on the client…they’re both empty.
My question is, why would I be able to connect and make calls to the SOAP endpoint without a problem through the WCFTestClient but not through the Add Service Reference method?
EDIT: It seems to be an issue with the references I have on the assembly I’m adding the service reference to. I’m referencing another class library (the same library exists on the service) and am getting this warning when I build my solution:
Warning 12 Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Referenced type 'MyNamespace.KPI.ChartObject`2, MyNamespace.KPI.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3e720b7e8a51f8d5' with data contract name 'ChartObjectOfdecimalZKPIPeriodaU4eboDJ' in namespace 'http://schemas.datacontract.org/2004/07/MyNamespace.KPI' cannot be used since it does not match imported DataContract. Need to exclude this type from referenced types.
It should be noted that this specific class is a generic class…I don’t know if this has anything to do with the error.
You need to follow your ABC’s:
An address that is exposed through HTTP just needs a deployment URL. Which the Internet Information System is handling all of that for you. However; if you attempt to use the
Service Referencewithout the proper definitions- it will not show. As it has no details of where it is going.Once you’ve defined that criteria it should appear per normal.
Update:
You can culminate SOAP and REST off the same Service Contract or you can separate them. In this example; I’ll separate them.
Create the Service:
Create the Service Contract for Rest:
In the above service; it is explicitly setting the message format.
Implement the Service: “Binding”
Configure the Service:
The above will set the service to Basic / Web Http.
After you’ve configured your
serviceBehavioryou’ll need to define the endpoint:This will configure your Rest Endpoint to the
webHttpBindingspecified above. Now you need to define your Soap.The above will go into your configuration; however at the time of consumption of the service- the endpoint name is required. The endpoints will be available at the Base Address / Soap Address. The binding used is specified.
Except we have only configured our Soap, not our Rest. So we need to specify our endpoint:
Our Rest Endpoint will be called at our Url (Base Address / Rest/ Add / Parameter / Parameter). We’ve specified our binds; and set our Rest Behavior.
When you put the whole thing together; it would look like:
Consuming:
To consume our Soap it is simple; straight forward. Make the Service Reference and make the call.
Except our Restful consumption is slightly different; especially since we have to Format it to Json. So we need to specify the name exactly.
Rest is going to rely on Json for De-serialization of the data.
The above will download the data using the Rest Uri. Deserialize that data; and become displayed.
Hopefully that helps clarify.
If the proper items aren’t created in your configuration file; then it will not allow the proper consumption. The ABC’s are critical in WCF. If it isn’t created in the configuration file you’ll need to programatically create them in the code.
Update:
As you see in this basic example; the binding and endpoint are both configured. You need to ensure that all of these are defined in both your server and client. It has to know where it is going. Does that make more sense?