Is Wcf Rest 'WebHttpBinding' Support
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] ?
I am getting null response of
OperationContext.Current.SessionId;
change the ServiceContract attribute as :
[ServiceContract(SessionMode = SessionMode.Required)]
Related
I have a WCF client calling a Java SOAP service (with TLS and MA incidentally).
The SOAP action is coming out as:
<a:Action s:mustUnderstand="1">http://schemas.xmlsoap.org/ws/2005/02/trust/RST/Issue</a:Action>
But I am trying to set it to
<a:Action s:mustUnderstand="1">urn:example:services:201005:SendMessage</a:Action>
I thought I could do this using the following OperationContract attribute...
[ServiceContract(Namespace = "urn:example:ns:201005", ConfigurationName = "IExampleService")]
public interface IExampleService : IDisposable
{
[OperationContract(Action = "urn:example:services:201005:SendMessage")]
[FaultContract(typeof(ExampleErrorInfo), Action = "urn:example:services:201005:SendMessage", Name = "ExampleErrorInfo")]
[XmlSerializerFormat(SupportFaults = true)]
ExampleResponse SendMessage(ExampleRequest request);
}
Why is my SOAP action still wrong?
This seems to be a WS-Trust handshake message, not your actual message. See http://schemas.xmlsoap.org/ws/2005/02/trust/tls/WSTrustForTLS.pdf , section 1.8.
I'm using Castle WCF Integration Facility and I have everything working properly for my first webHttp endpoint. For this endpoint to work, it requires that the endpoint have the WebHttpBehavior enabled. I was able to achieve this using:
container.Register(Component.For<IEndpointBehavior>()
.ImplementedBy<WebHttpBehavior>());
This becomes a problem when I try to enable a second endpoint using BasicHttpBinding which is not compatible with the WebHttpBehavior.
Is there someway to specify that the IEndPointBehavior registration above is only applicable to a certain endpoint?
This is my full installer for the service:
container.AddFacility<WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero)
.Register(Component.For<IDiagnosticService>()
.ImplementedBy<DiagnosticService>()
.Named("DiagnosticService")
.LifestyleTransient()
.AsWcfService(new DefaultServiceModel()
.Hosted()
.AddEndpoints(WcfEndpoint.BoundTo(new WebHttpBinding()).At("json"))
.AddEndpoints(WcfEndpoint.BoundTo(new BasicHttpBinding()).At("soap"))
.PublishMetadata(o => o.EnableHttpGet())));
container.Register(Component.For<IEndpointBehavior>()
.ImplementedBy<WebHttpBehavior>());
Ok. I finally figured this out. Turns out that the majority of my problem had to do with the Azure emulation environment rather than Castle WCF Integration. The answer is pretty straight forward -- just setup the ServiceEndpoint instances and use the WcfEndpoint.FromEndpoint() method.
Here is my working installer:
String internalEndpointAddress = string.Format("http://{0}/DiagnosticService.svc",
RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Endpoint1"].IPEndpoint);
// This ContractDescription instance must be used for both endpoints in this case
ContractDescription description = ContractDescription.GetContract(typeof(IDiagnosticService));
// Create JSON webHTTP Binding
WebHttpBinding webhttpbinding = new WebHttpBinding();
string jsonURI = internalEndpointAddress + "/json";
EndpointAddress jsonEndpointAddress = new EndpointAddress(new Uri(jsonURI));
ServiceEndpoint jsonEndpoint = new ServiceEndpoint(description, webhttpbinding, jsonEndpointAddress);
jsonEndpoint.Behaviors.Add(new WebHttpBehavior());
// Create WSHTTP Binding
WSHttpBinding wsHttpBinding = new WSHttpBinding();
string soapURI = internalEndpointAddress + "/soap";
EndpointAddress soapEndpointAddress = new EndpointAddress(new Uri(soapURI));
ServiceEndpoint soapEndpoint = new ServiceEndpoint(description, wsHttpBinding, soapEndpointAddress);
container.AddFacility<WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero)
.Register(Component.For<IDiagnosticService>()
.ImplementedBy<DiagnosticService>()
.Named("DiagnosticService")
.LifestyleTransient()
.AsWcfService(new DefaultServiceModel()
.Hosted()
.AddEndpoints(WcfEndpoint.FromEndpoint(jsonEndpoint))
.AddEndpoints(WcfEndpoint.FromEndpoint(soapEndpoint))
.PublishMetadata(o => o.EnableHttpGet())));
I have a WCF REST Service with teh following URL:
http:/localhost/GetAllOrders
but the factorychannel always genereates the Uri to http:/localhost/Service.svc/GetAllOrders/GetAllOrders
Here is my client factory channel:
Uri address = new Uri("http:/localhost/Service.svc/GetAllOrders");
var factory = new System.ServiceModel.Web.WebChannelFactory<App.WebService.IOrderSvc>(address);
var webHttpBinding = factory.Endpoint.Binding as System.ServiceModel.WebHttpBinding;
App.WebService.IOrderSvc service = factory.CreateChannel();
var orders = service.GetAll(); // this one throwing an error since the URI has become http:/localhost/Service.svc/GetAllOrders/GetAllOrders
and here is the service contract:
[WebGet(UriTemplate = "GetAllOrders")]
[OperationContract]
List<Order> GetAll();
any idea why the Uritemplate being added twice?
The Uri is wrong - it should be service's Uri. You should write:
Uri address = new Uri("http:/localhost/Service.svc/");
I created a simple function
[OperationContract]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)]
string Start();
Definition,
public String Start()
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
return serializer.Serialize("Check");
}
From browser using Javascript/Jquery,
http://localhost/service1.svc tells me I have created a service and all other info.. Looks fine.
I'm trying to call this using
http://localhost/service1.svc/Start
I get a 400 bad request for this call. I hope I'm not doing something totally wrong here. I should be able to access WCF service from browser right?
I tried looking a lot before I thought of posting. But I'm unable to get this basic thing working is frustrating me.
EDIT & UPDATE
Now I'm at this stage. The service page is telling me that the metadata service is disabled and is asking me to insert the following text
<serviceMetadata httpGetEnabled="true" />
I inserted the text - but still it shows the same text!! This is getting too confusing now..
Try to change POST with GET and restart the request
Works for me. I created WCF Rest Service.
I use URL which looks like http://localhost:8080/Service1/Start
Here is the code:
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Web.Script.Serialization;
namespace WcfRestService1
{
// Start the service and browse to http://<machine_name>:<port>/Service1/help to view the service's generated help page
// NOTE: By default, a new instance of the service is created for each call; change the InstanceContextMode to Single if you want
// a single instance of the service to process all calls.
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
// NOTE: If the service is renamed, remember to update the global.asax.cs file
public class Service1
{
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json)]
public string Start()
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
return serializer.Serialize("Check");
}
}
}
I have a service exposed as WCF via NServiceBus. Ultimately, I'd like to call to this service from silverlight. My WCF Service Interface looks like this:
[ServiceContract]
public interface ISettingsService
{
[OperationContract(Action = "http://tempuri.org/IWcfServiceOf_RequestSettingsMessage_SettingsResponseMessage/Process", ReplyAction = "http://tempuri.org/IWcfServiceOf_RequestSettingsMessage_SettingsResponseMessage/ProcessResponse") ]
SettingsResponseMessage FetchSettings(RequestSettingsMessage request);
}
My NSB WCF service is defined as:
public class CoreService : WcfService<RequestSettingsMessage, SettingsResponseMessage>
{
}
When I invoke the FetchSettings method on the service, I get an exception:
System.TypeInitializationException: The type initializer for 'NServiceBus.WcfSer
vice`2' threw an exception. ----> System.InvalidOperationException: Centerlink.Services.Core.Msg.Settings.SettingsResponseMessage must be an enum representing error codes returned by the server.
It seems that the WcfService<> class is restricting the return type of a WCF method to be an enum. How can I have my service return something other than an enum? Do I need to create a custom implementation of NServiceBus.WcfService<>?
You need to create your own wcf service for that scenario.
More details here:
http://tech.groups.yahoo.com/group/nservicebus/message/6295