I have created a wcf service, but when I run , then it show error like this.
I have change the name class and interface name using rename tool.
Here is code for service.cs class
public class MyTest : MyServices
{
public string MyTask1(string a)
{
return "Hello " + a;
}
public string MyTask2(DataContract1 dc)
{
return "Hello " + dc.fname;
}
}
Here is the code for my interface :
[ServiceContract]
public interface MyServices
{
[OperationContract]
string MyTask1(string myValue);
[OperationContract]
string MyTask2(DataContract1 dcValue);
}
// Use a data contract as illustrated in the sample below to add composite types to service operations.
[DataContract]
public class DataContract1
{
string firstName;
string lastName;
[DataMember]
public string fname
{
get { return firstName; }
set { firstName = value; }
}
public string lname
{
get { return lastName; }
set { lastName = value; }
}
}
I have edited my web.config file, and added these lines (I read it in black book)
<service name="Service" behaviorConfiguration="ServiceBehavior">
<!--Service EndPoints-->
<endpoint address="" binding="wsHttpBinding" contract="MyServices">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadatExchange"/>
</service>
Here is my system.servicemodel code
<system.serviceModel>
<services>
<!-- My Custimization -->
<service name="Service" behaviorConfiguration="ServiceBehavior">
<!--Service EndPoints-->
<endpoint address="" binding="wsHttpBinding" contract="MyServices">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadatExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
1) in legacy web service we create proxy using wsdl. WSDL expose web service meta data. in wcf another term comes that mex endpoint which also expose meta data but wsdl is still live in wcf.i am new in wcf hence i am confusing what is the difference between wsdl & mex endpoint?
It's pretty the same thing but mex is designed to support non-HTTP protocols and for advanced configuration/security scenarios. WSDL is the legacy way and MEX is the new improved version with WCF.
2) what is the meaning of httpGetEnabled="false" or httpGetEnabled="true"
It will expose metadata via wsdl through the defautl url, even if you don't have defined a mex endpoint for your service.
3) if i set httpGetEnabled="false" then what will happen? does it mean that client will not be able to add service reference from IDE? but i set httpGetEnabled="false" and saw client can add service reference. so it is very confusing for me that what httpGetEnabled is false or true does ?
A client can add a reference in VS only if httpGetEnabled/httpsGetEnabled is enable or if you have define a mex endpoint in the configuration of your service. The best practice is to expose metadata on dev environnement but not on production. You can also distribute your service contracts via separate assemblies and use ChannelFactory.
4) one guy said :- MEX and WSDL are two different schemes to tell potential clients about the structure of your service. So you can choose to either make your service contracts public as (MEX) or WSDL. if the above statement is true then tell me when to use MEX & when to use WSDL?
A WSDL is generally exposed through http or https get urls that you can't really configure (say for security limitations or for backward compatibility). MEX endpoints expose metadata over configurable endpoints, and can use different types of transports, such as TCP or HTTP, and different types of security mechanisms.
So MEX are more configurable, while WSDL is more interoperable with older versions of clients and non-.net clients that work with WSDLs.
5) how could i disable mex and expose my service through only WSDL
Do not specifiy a mex endpoint in your config and use httpGetEnabled
6) WSDL support all bidning like wshttp,wsdualhttp or tcp etc...
Exposing metadata is totally different that invoking the service.
UPDATE
re you try to mean that there should be no mex endpoint related entry in config and httpgetenable would look like
Yes, you don't have to specify a mex endpoint AND httpGetEnabled. Only one is required to expose metadata. Do not specifiy httpGetUrl as this is depending on your hosting environment.
you said mex is configurable but wsdl is not. what r u trying to means mex is configurable...please discuss what kind of configuration mex support & how to configure.
MEX endpoints are special endpoints that allow clients to receive the service’s metadata by using SOAP messages instead of http get requests. You can create MEX endpoint that can be accessed through http, https, tcp, and even named pipes. HttpGetEnable allow you to expose metadata through HTTP GET method, usually the service’s address with the suffix of ‘?wsdl'
MEX and WSDL both output nearly the same thing.
In most cases there is no need for MEX endpoint – using WSDLs with http get is usually enough.
I understand your intention to understand this part, but do not spend to many times on this : there are so many others complicated features !
Spelling mistake I guess..
IMetadatExchange -- > IMetadataExchange
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadatExchange"/>
try this...
<system.serviceModel>
<services>
<!-- My Custimization -->
<service name="Service" behaviorConfiguration="ServiceBehavior">
<!--Service EndPoints-->
<endpoint address="" binding="wsHttpBinding" contract="MyServices">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
Related
I have been digging for hours to solve this problem, but have not gotten anywhere.
I am attempting to configure a service and everything compiles, but I am getting some warnings and the service cannot be found when attempting to create a reference.
The specific messages are:
WCF configuration validation warning: The 'name' attribute is invalid - The value 'VisionProRegistrationService.VisionProRegistrationSvc' is invalid according to its datatype 'serviceNameType'.
and
WCF configuration validation warning: The 'contract' attribute is invalid - The value 'VisionProRegistrationService.IVisionProRegistrationSvc' is invalid according to its datatype 'serviceContractType'.
The config file code is as follows:
<system.serviceModel>
<services>
<service behaviorConfiguration="VisionProRegistrationService.VisionProRegistrationServiceBehavior" name="VisionProRegistrationService.VisionProRegistrationSvc">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="" name="NetTcpBinding_IVisionProRegistrationService" contract="VisionProRegistrationService.IVisionProRegistrationSvc">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" name="MexBinding_IVisionProRegistrationService" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8527/VisionProRegistrationService"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="VisionProRegistrationService.VisionProRegistrationServiceBehavior">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
<behavior name="mexbehavior">
<serviceMetadata/>
</behavior>
</serviceBehaviors>
</behaviors>
The contract looks like this:
namespace VisionProRegistrationService { [ServiceContract] public interface IVisionProRegistrationSvc { [OperationContract] bool Initialize(ServiceDataContracts.ModuleConfigurationData config, List<ServiceDataContracts.TcpClientData> clients,
string savedJobFilePath = null, string savedCalFilePath = null, int savedExposureTimeUs = 250, bool savedStrobePulseHi = true);
And finally, the service class itself looks like this:
namespace VisionProRegistrationService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
public class VisionProRegistrationSvc : IVisionProRegistrationSvc
{
This is not posting as cleanly as I would like, but I hope it is enough.
Everything I had found in the past indicated a mismatch with the interface or class name, but those all seem correct. I can't find anything officially on this. Does anyone have any suggestions?
Thanks!
Running the test client provided the information I needed to solve the problem. One of the classes in the data contract contained multidimensional arrays. Thanks for the help! I was not getting anywhere without the more detailed debugging information.
I googled for 2 days and tried almost everything, but I still can't get this stuff working.
I have 2 WCF services. I use self-hosting, not IIS(for some reasons IIS isn't working for me). One is duplex, another is standart. Here are their contracts:
Duplex:
[ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(IServiceCallback))]
public interface IClientService
{
[OperationContract(IsOneWay = true)]
void SolveTask(string pipelineName, string data);
[OperationContract(IsOneWay = true)]
void GenerateTask(List<GeneratorMethod> parameters);
[OperationContract]
bool Ping();
}
public interface IServiceCallback
{
[OperationContract(IsOneWay = true)]
void SendResult(SampleAnswer[] answers);
[OperationContract(IsOneWay = true)]
void RequestGeneratorParameters();
[OperationContract(IsOneWay = true)]
void SendGenerationResult(string text);
}
Classic:
[ServiceContract]
public interface IServerManagementService
{
[OperationContract]
[FaultContract(typeof(XmlError))]
[FaultContract(typeof(UnknownError))]
[FaultContract(typeof(InitializationError))]
void InitializeServer();
[OperationContract]
void StartServer();
[OperationContract]
void StopServer();
[OperationContract]
void RestartServer();
}
I have following config:
<configuration>
<services>
<service behaviorConfiguration="Service" name="LinProgWebServer.ClientService">
<endpoint address="net.tcp://localhost:8078/LinProgWebServer/ClientService"
binding="netTcpBinding" bindingConfiguration="netTcpEventBinding"
contract="LinProgWebServer.IClientService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/Design_Time_Addresses/LinProgWebServer/ClientService" />
</baseAddresses>
</host>
</service>
<!--сервис управления сервером-->
<!--<service behaviorConfiguration="Service" name="LinProgWebServer.ServerManagementService">
<endpoint address="net.tcp://localhost:8079/LinProgWebServer/ManagementService"
binding="netTcpBinding" bindingConfiguration="netTcpEventBinding"
contract="LinProgWebServer.IServerManagementService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/LinProgWebServer/ManagementService" />
</baseAddresses>
</host>
</service>-->
</services>
<behaviors>
<serviceBehaviors>
<behavior name="Service">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
Now i have a big trouble: I CAN find classic service via add service reference and CANNOT find duplex service. I tried netstat and it says that both services are listening on their ports. What am i doing wrong?
Here is exception i get:
There was an error downloading 'http://localhost:8731/Design_Time_Addresses/LinProgWebServer/ClientService/_vti_bin/ListData.svc/$metadata'.
The request failed with HTTP status 405: Method Not Allowed.
Metadata contains a reference that cannot be resolved: 'http://localhost:8731/Design_Time_Addresses/LinProgWebServer/ClientService'.
There was no endpoint listening at http://localhost:8731/Design_Time_Addresses/LinProgWebServer/ClientService that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
The remote server returned an error: (404) Not Found.
If the service is defined in the current solution, try building the solution and adding the service reference again.
I'll be grateful for any help.
Make sure you .svc file has the correct name of the class you added in your Service Reference
if you added a service called 'Foo' it should look like:
<%# ServiceHost Language="C#" Debug="true" Service="Foo" CodeBehind="Foo.svc.cs" %
Also, make sure you have
In your web.config
I'm not sure whether this is going to be usefull. All my configs and services were fine, but i had a mistace in types, which were involved in work of wcf services, i haven't marked one of the types as datacontract. U'm very surprised why service started without erros and showed me such not informative messages. Also, thanks Yuval for reminding about InstanceContextMode attribute.
Add this to the area where you setup you set up your endpoint and reference your service classes:
//config service metadata
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
ServiceMetadataBehavior mb = new ServiceMetadataBehavior();
ServiceHost.Description.Behaviors.Add(mb);
if (bUseSSL) {
mb.HttpsGetEnabled = true;
mb.HttpGetEnabled = false;
ServiceHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpsBinding(), "mex");
} else {
mb.HttpsGetEnabled = false;
mb.HttpGetEnabled = true;
ServiceHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
}
You should not be using the same URL that you were using to host it in the dev environment. Localhost means nothing outside of the machine, anyway. Use the IP address of the machine and also -- you might have to use netsh to open the port on that machine.
I have complete exhausted resources on trying to get NetNamedPipeBinding for my WCF Service working. I was able to get the NorthwindService example working found here.
For the NorthwindService example, I have the following:
namespace NorthwindServices
{
public class Customer : ICustomer
{
public string GetCustomerName(int CustomerID)
{
return CustomerID.ToString();
}
}
}
namespace NorthwindServices
{
[ServiceContract]
public interface ICustomer
{
[OperationContract]
string GetCustomerName(int CustomerID);
}
}
And the configuration for the example is the following:
<system.serviceModel>
<services>
<service name="NorthwindServices.Customer"
behaviorConfiguration="ServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="net.pipe://localhost/NorthwindServices/Customer"/>
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="CustomerService" binding="netNamedPipeBinding" contract="NorthwindServices.ICustomer"/>
<endpoint address="CustomerService/mex" binding="mexNamedPipeBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="False" httpsGetEnabled="False"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
I have an IIS Site defined for this with the details below:
So when I go to 'Add Service Reference' I can pull in the reference perfectly fine.
However, when I try to do the same in my actual application, I still cannot seem to figure it out. I am unable to pull in the reference.
The site structure is the following:
The top level site is an MVC site, and there is an "API" virtual directory below it where the service resides that I am trying to expose over NetNamedPipeBinding.
The bindings for the site are the following:
The config for the service I am trying to expose over named pipes is the following:
<system.serviceModel>
<services>
<service name="Site.API.Service.WorkItemQueueService"
behaviorConfiguration="ServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="net.pipe://localhost/WorkItemQueueService"/>
</baseAddresses>
</host>
<endpoint address="QueueService"
binding="netNamedPipeBinding"
contract="Site.API.Service.IWorkItemQueueService"/>
<endpoint address="QueueService/mex"
binding="mexNamedPipeBinding"
contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="True" aspNetCompatibilityEnabled="True"/>
The service implementation is the same as the customer service above, but obviously renamed to match the configuration above.
When I try to add a service reference, or find the metadata for this, It cannot find it.
IMPORTANT - All of the pre configuration items such as starting the Net Pipe listerner and role service have been completed, hence the NorthwindServices example works.
maybe you can help me set up my WCF service.
First, here is my config file:
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings />
<services>
<service name="AuthenticatorService.Authenticator">
<endpoint address="auth" binding="basicHttpBinding" bindingConfiguration=""
name="AuthEndpoint" contract="AuthInterface.IAuthenticator" />
<endpoint address="mex" binding="mexHttpBinding" name="MetadataEndpoint"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
And this is how I call my service from c#:
//This creates a link to the WCF service using basicHttpBingind
httpFactory = new ChannelFactory<IAuthenticator>(new BasicHttpBinding(), new EndpointAddress("http://myUrl/auth.svc"));
httpProxy = httpFactory.CreateChannel();
It worked fine when I was doing this on localhost but now it keeps telling me no endpoint was found.
Also, the server generated the following error:
System.ServiceModel.EndpointNotFoundException: There was no channel actively listening at 'http://myURL/auth.svc/$metadata'. This is often caused by an incorrect address URI. Ensure that the address to which the message is sent matches an address on which a service is listening.
Im really confused, I have no idea why this is happening. Do I need to create another service file for the metadata exchange?
Do I need to set a baseAddress?
Thanks
How did you deploy the service? I assume the service is running in IIS on your box - did you try hitting the service URL (http://myUrl/auth.svc) in a browser to see if it is indeed up?
I'm working with an interface generated by from a wsdl, and I'm running into an issue when trying to host my service as a Windows Service.
The following line appears above the interface. Unless I change it from
[System.ServiceModel.ServiceContractAttribute(Namespace="http://xxxxxx.com/", ConfigurationName="IService")]
to
[System.ServiceModel.ServiceContract]
I can't start the Windows service that hosts my program (the error log in the event viewer says the contract IService could not be found in the list of contracts implemented by Service.) I'm listing the endpoint my app.config file as follows:
endpoint address=""
binding="basicHttpBinding"
contract="Service.IService"
This also happens when I change the contract to "http://xxxxxxx.com/IService" as it appears in the ServiceContractAttribute. Any ideas about how I can fix this?
The service portion of the config file:
<service name="Service.Service"
behaviorConfiguration="myServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/Service"/>
</baseAddresses>
</host>
<endpoint address=""
binding="basicHttpBinding"
contract="Service.IService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="Service.IService" />
</service>
<behaviors>
<serviceBehaviors>
<behavior name="myServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="True"/>
</behavior>
</serviceBehaviors>
</behaviors>
The contract attribute of the endpoint element in config needs to match the value of the ConfigurationName property of the ServiceContractAttribute in the code. So in your case just change the config so that it reads contract="IService" and you should be good.
It appears that it can't find the endpoint. Have you used a terminal to interrogate the endpoint to see if it is responding at the supplied address?
"itowlson" is most likely on the right track with his comment - your original service contract defines a configuration name:
[ServiceContract(Namespace="http://xxxxxx.com/",
ConfigurationName="IService")]
but there is no such service configuration in your config section.
Try changing this:
<service name="Service.Service"
to
<service name="IService"
(or alternatively, change the ServiceContract to:
[ServiceContract(Namespace="http://xxxxxx.com/",
ConfigurationName="Service.Service")]
These two names need to match! Or simply leave out the configuration name from the service contract:
[ServiceContract(Namespace="http://xxxxxx.com/")]
and in this case, the service config will be found based on the Namespace.ServiceClassName pattern of the service class that actually implements the service contract.
Either way, you need to make sure the information in the ServiceContract attribute and the config file match up.
Marc