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!
Related
I am an android developer. I want to create an android application which fetches the xml response from a WCF web service using soap. I have created a WCF web service, in which it fetches the XML document and return the content of that document. Here I dont know how to consume that content in android. Moreover, I am new to WCF and I am confused whether I am doing it right or wrong. Any help would be appreciated.
IService.cs
namespace WcfXML
{
[ServiceContract (Namespace="http://tempuri.org/")]
public interface IService1
{
[OperationContract, XmlSerializerFormat]
XmlElement GetData();
}
}
Service1.svc
namespace WcfXML
{
public class Service1 : IService1
{
public XmlElement GetData()
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(#"D:\defaultGraphProperties.xml");
return xmlDoc.DocumentElement;
}
}
}
After creating this, when I run(F5), I am not able to invoke the method. How can I consume this web services in android? Please Help!!!!
You need to add configuration for webHttpBinding in web.config under the <Bindings>.
Then add the below code in web.config under the <System.serviceModel>
<services>
<service name="Test_WcfService.Service1" behaviorConfiguration="ServiceBehavior">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="webHttpBindingConfiguration" behaviorConfiguration="web" contract="Test_WcfService.IService1"></endpoint>
<endpoint address="Service1.svc" binding="basicHttpBinding" bindingConfiguration="basicHttpBindingConfiguration" contract="Test_WcfService.IService1"></endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"></endpoint>
</service>
</services>
<bindings>
<webHttpBinding>
<binding name="webHttpBindingConfiguration" maxReceivedMessageSize="2147483647" />
</webHttpBinding>
<basicHttpBinding>
<binding name="basicHttpBindingConfiguration" maxReceivedMessageSize="2147483647" />
</basicHttpBinding>
</bindings>
<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>
<endpointBehaviors>
<behavior name="web">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
After doing this changes in web.config you will be able to consume the wcf service from Browser.
Replace the Test_WcfService.Service1 and Test_WcfService.IService1 with your WCF Service name and interface.
To consume the WCF Service , you will have to do a Soap Request from Android.
Also if possible share your demo wcf service i will make the necessary configuaration changes at my end.
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,
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" />
I am trying to fully understand how adding an Interface in WCF affects the URI of the methods. I have a ServiceContract defined like this:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceContract]
public class DataService
{
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
public List<List<string>> ListTestMethod()
{
return new List<List<string>>
{
new List<string> {"0", "Test String 1"},
new List<string> {"1", "Test String 2"},
new List<string> {"2", "Test String 3"}
};
}
}
In my web.config file I have the following:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="epBehavior" >
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="serviceBehavior">
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="DataService"
behaviorConfiguration="serviceBehavior">
<endpoint address=""
behaviorConfiguration="epBehavior"
binding="webHttpBinding"
contract="DataService" />
</service>
</services>
</system.serviceModel>
When I test the method via a browser:
http://localhost/DataService.svc/ListTestMethod
I get this which is the expected result:
[["0","Test String 1"],["1","Test String 2"],["2","Test String 3"]]
So now I would like to add an interface to the code behind with something like this:
[ServiceContract]
public interface IDataService
{
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
List<List<string>> ListTestMethod();
}
And of course go back to the DataService class and add the appropriate ": IDataService" implementation while removing the adorners that are now already in the Interface. Here is where I have trouble as the URL above no longer works.
I tried updating web.confg to this (note changes to name and contract attributes):
<services>
<service name="IDataService.DataService"
behaviorConfiguration="serviceBehavior">
<endpoint address=""
behaviorConfiguration="epBehavior"
binding="webHttpBinding"
contract="IDataService.DataService" />
</service>
</services>
Which seems to get the service going again but I cant actually get to the methods and if I add enable serviceMetadata it can no longer get to the metadata (it can in the original version). I have tried all kinds of combinations of the web.config and the URL but cannot seem to get my arms around it. How do I wire in the new Interface appropriately?
UPDATE
Thanks to venerik I got it working but changing the endpoint to point at the interface but leaving the service as is:
<services>
<service name="DataService"
behaviorConfiguration="serviceBehavior">
<endpoint address=""
behaviorConfiguration="epBehavior"
binding="webHttpBinding"
contract="IDataService.DataService" />
</service>
</services>
I'm not fully confident of this answer but I think your web.config should point to the interface:
<endpoint
...
contract="IDataService"/>
Your service host file should point to the concrete implementation:
<% #ServiceHost Language=C# Service="SomeNamespace.DataService" %>
Info about #ServiceHost
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.