wcf client generated code requires constructor parameters - c#

When I follow the link the example it gives me
class Test
{
static void Main()
{
InternalCommunicationClient client = new InternalCommunicationClient();
// Use the 'client' variable to call operations on the service.
// Always close the client.
client.Close();
}
}
But when I copy this code into a console, the InternalCommunicationClient requires
(InstanceContect callback) as a parameter.
I have done wcf 2 years ago and this wasn't there back then. please help
Here is the web.conf code
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" >
<services>
<service name="Workflowms.Web.webservices.Internalcommunication.InternalCommunication">
<endpoint address="" binding="wsDualHttpBinding" contract="Workflowms.Web.webservices.Internalcommunication.IInternalCommunication" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>

Follow these steps,
Expose end points
Make a Service Reference in your code
Use your above mentioned cod,

Related

Adding WCF service reference in ASP.NET MVC app fails

I'm trying to add a WCF service to my ASP.NET MVC application. After setting it up, I get an error whenever I want to test it.
Here is my code:
BackgroundTask.svc
public class BackgroundTask : IBackgroundTask
{
public void ShutdownVm()
{
}
public void UpdateTable()
{
}
}
IBackgroundTask.cs
[ServiceContract]
public interface IBackgroundTask
{
[OperationContract]
void ShutdownVm();
[OperationContract]
void UpdateTable();
}
Web.config
<system.serviceModel>
<services>
<service behaviorConfiguration="bgtBehaviour" name="IsolutionsAzureManager.Controllers.BackgroundTask">
<endpoint address="BackgroundTask" binding="basicHttpBinding"
bindingConfiguration="" name="" contract="IsolutionsAzureManager.Controllers.IBackgroundTask" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:44304/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="bgtBehaviour">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
So, whenever I want to test my WFC service, I get this error:
Error: Cannot obtain Metadata from https://localhost:44304/Controllers/BackgroundTask.svc
Error: The HTML document does not contain Web service discovery information.
Can anyone see the mistake?
Because you are attempting to acquire the mex endpoint over Https, you'll also need to switch to mexHttpsBinding and
to enable the httpsGetEnabled setting:
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
Alternatively, obtain the endpoint via http (http://localhost:44304/Controllers/BackgroundTask.svc) and then just switch back to https once the client has built the service reference artifacts.

WCF + Xml-Rpc don't work

I have a classic WCF webservice. Few weeks ago, in order to answer to a client demand, I added Rest management to my webservice.
But, at the beginning of the week, another client said to me its system can only manage XML-RPC. So he needs to connect to my webservice via this protocol.
So I found this : Configuring XML-RPC behavior for IIS-hosted .SVC file?
First, I compiled the Microsoft.Samples.XmlRpc in order to add it to my project. Two Dll appears : Microsoft.Samples.XmlRpc & Microsoft.ServiceModel.XmlRpc
Then, I created a XmlRpcEndpointBehaviorExtension class, the same as the post above :
namespace WsZendesk
{
public class XmlRpcEndpointBehaviorExtension : BehaviorExtensionElement
{
protected override object CreateBehavior()
{
// this comes from Microsoft.Samples.XmlRpc
return new XmlRpcEndpointBehavior();
}
public override Type BehaviorType
{
get { return typeof(XmlRpcEndpointBehavior); }
}
}
}
After, I created my interface for Xml-Rpc :
namespace WsZendesk
{
[ServiceContract]
public interface IWsZendeskRpc
{
[OperationContract(Action = "wszendesk.GetUserIdFromBarcode")]
void GetUserIdFromBarcode(String sXmlIn, out String sXmlOut);
}
}
Finaly, I modified my web.config in order to allow RPC :
<system.serviceModel>
<services>
<service name="WsZendesk.WsZendesk" behaviorConfiguration="WsZendeskServiceBehavior">
<endpoint address="rest" behaviorConfiguration="restfulBehavior"
binding="webHttpBinding" bindingConfiguration="" name="RESTEndPoint"
contract="WsZendesk.IWsZendeskRest" />
<endpoint address="xmlrpc" behaviorConfiguration="xmlRpcBehavior"
binding="webHttpBinding" bindingConfiguration="" name="RPCEndPoint"
contract="WsZendesk.IWsZendeskRpc" />
<endpoint address="" behaviorConfiguration=""
binding="basicHttpBinding" bindingConfiguration="" name="SOAPEndPoint"
contract="WsZendesk.IWsZendesk" />
</service>
</services>
<extensions>
<behaviorExtensions>
<add name="xmlRpc"
type="WsZendesk.XmlRpcEndpointBehaviorElement, WsZendesk" />
</behaviorExtensions>
</extensions>
<behaviors>
<endpointBehaviors>
<behavior name="restfulBehavior">
<webHttp />
</behavior>
<behavior name="xmlRpcBehavior">
<xmlRpc />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="WsZendeskServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Visual Studio said he don't know the child element 'xmlRpc'. So, when I try to launch my webservice, the same error appears during the execution.
Anybody can help me to use Xml-Rpc with my existing webservice ?
For information, my project is in C# 4.
It was not this:
<add name="xmlRpc"
type="WsZendesk.XmlRpcEndpointBehaviorElement, WsZendesk" />
But this:
<add name="xmlRpc"
type="WsZendesk.XmlRpcEndpointBehaviorExtension, WsZendesk" />

WCF NetNamedPipeBinding Service NorthwindService example vs MyService

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.

Error: Cannot obtain Metadata from WCF service

I have a successfully running WCF service that I can call using javascript. However I want to invoke it using the WCF test client and im having difficulty doing this. I am told that I need to make sure I have enabled meta data publishing at the specified address. After reading the documentation I just cant see what im meant to do this is my configuration:
<system.serviceModel>
<services>
<service name="CommentSessionIDWCFService"
behaviorConfiguration="CommentSessionIDBehavior">
<endpoint
address=""
behaviorConfiguration="CountryProvinceBehavior"
binding="webHttpBinding"
contract="ICommentSessionIDWCFService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CommentSessionIDBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="CountryProvinceBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
I've read other posts but I can't see what to populate and I just keep getting errors. Q's..
Am I right in saying that I need to configure a complete new service in my config to show the metadata?
What do I add to the configuration to make this meta data published so I can invoke with the client?
You need a metadata endpoint for your service, here`s an example.
<services>
<service name="MyService" behaviorConfiguration="MEX">
<endpoint
address="http://localhost:8000/MEX"
binding="mexHttpBinding"
contract="IMetadataExchange"
/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MEX">
<serviceMetadata/>
</behavior>
</serviceBehaviors>
</behaviors>
I had a similar problem after changing the config file in the TestClient with right click and "edit with svceditor" to increase my maxbuffersize. If someone did that mistake as well, try rebuilding your project.
Add
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
Set httpGetEnabled to true and set the includeExceptionDetailInFaults to false:
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>

Hosting a WCF Atom feed in IIS

I have a simple Atom 1.0 feed that I've generated, similar to the example shown on MSDN.
However, instead of creating a host and testing the feed via console application, as in the example, I'm attempting to create the endpoint via configuration.
My configuration is as follows:
<system.serviceModel>
<services>
<service
name="MyNamespace.MyService"
behaviorConfiguration="returnFaults">
<endpoint
address=""
binding="basicHttpBinding"
contract="MyNamespace.IMyGenericService">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="returnFaults">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
When I run my WCF service, I'm able to access the stock description page and even use this address as a service reference. However, if I attempt to call the method that returns the feed(http://localhost:SomeVSPort/MyService/GetFeed), I get a blank page with no errors. Setting a breakpoint in the method was unsuccessful as the method does not seem to be getting called.
My question is, how should I be exposing this feed for hosting via IIS? Should I be using a different configuration for my endpoint?
For reference, my service declaration follows:
namespace MyNamespace
{
[ServiceContract]
public interface IMyGenericService
{
[OperationContract]
[WebGet]
Atom10FeedFormatter GetFeed();
}
public class MyService: IMyGenericService
{
public Atom10FeedFormatter GetFeed()
{
SyndicationFeed feed = new SyndicationFeed();
//SimpleEntry is a local class that holds location information in a GeoRSS Simple format.
IList<SimpleEntry> entries = new List<SimpleEntry>()
{
new SimpleEntry() { ID = "1", Point = "45.256 -71.92", Title = "Point 1" },
new SimpleEntry() { ID = "2", Point = "-71.92 45.256", Title = "Point 2" }
};
feed.Items = entries
.Select(e => new SyndicationItem()
{
Content = new XmlSyndicationContent(
"application/xml",
new SyndicationElementExtension(e)),
Title = new TextSyndicationContent(e.Title),
Id = e.ID
});
return new Atom10FeedFormatter(feed);
}
}
}
You're mixing up SOAP (via the basicHttpBinding in your config) and REST (using the AtomFeedFormatter, and the [WebGet] attribute on your operation contract).
You need to choose one or the other. Since you want Atom, I assume you really want webHttpBinding in your config:
<system.serviceModel>
<services>
<service
name="MyNamespace.MyService"
behaviorConfiguration="returnFaults">
<endpoint
address=""
behaviorConfiguration="RESTBehavior"
binding="webHttpBinding"
contract="MyNamespace.IMyGenericService">
</endpoint>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="RESTBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="returnFaults">
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Since REST doesn't have things like WSDL and so on, you can get rid of any MEX related stuff, too - just plain REST.
Check out the WCF REST Developer Center on MSDN for a lot of very useful and informative additional resources!

Categories