CallBack Contract and Binding - c#

I have my service on a web site. I try to run this example, first just the server part:
:What steps do I need to take to use WCF Callbacks?
But I get this message: "Contract requires Duplex, but Binding 'BasicHttpBinding' doesn't support it or isn't configured properly to support it."
The Web.config file, doesn't have definitions such 'BasicHttpBinding'. It only has more general defitions. Do i have to add lines to it, or there is a more simple way. Many thanks.

Related

C# Calling Web Services to different URLs

I'm new to Web Services from C#, but have worked C# for years, just never needed to use Web Services. Due to privacy issues, I can't disclose actual URL, but there is a test server and a production server where the web services are identical in all other respects, and the services were written / managed by another entity.
https://LiveSite.SomeDomain.com/FolderInWebSite/TestWebServiceSoapHTTP
and
https://TestSite.SomeDomain.com/FolderInWebSite/TestWebServiceSoapHTTP
Do I need to create two separate web references to the project and create different instances of them to go, or can I via some property just change which URL version it is sending data to.
Additionally, not being familiar working web services, I see the classes as Visual Studio imported. I can create instances of the classes and set the applicable properties (int, dates, strings, string[] arrays, etc). But not seeing how to actually say ... Go send it now. and then getting the response back.
I've done this from an older application with another language and was doing direct with HTTP and SOAP where I was able to make my own connection to the URL, build the body of the SOAP message, then send it.
Just use the "Url" property.
var myProxy = new MyProxy();
myProxy.Url = "http://foo.com/myservice";
Edit for second part of the question:
There should be a method for each action exposed the API that you can call. For example if the API exposes a MyAction that takes a string, the code generator should have generated a method that you can use like so:
myProxy.MyAction("hello");

Host WCF in Windows Forms: Error when opening the host

I am trying to start and stop a WCF service library through a windows desktop application but got stuck. I cannot start it because it gives me error in the shost.Open();
Code:
private void startwcfedcHost()
{
ServiceHost shost = new ServiceHost(typeof(WcfServiceLibrary.Service));
shost.Open();
}
Error:
Service 'WcfServiceLibrary.Service' has zero application (non-infrastructure)
endpoints.
This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.
But when I try to run my wcf service it works, How can I fix this issue?
Since you don't specify the endpoints via code, you need to specify them via configuration. What you probably have is a missing configuration file. Change the Main method (if a console application; something like the Page_Loaded event if you're writing a windows app) to print the following value:
AppDomain.CurrentDomain.SetupInformation.ConfigurationFile
That will show the name that the application expects its configuration file to be. Once you have that, make sure that that file exists, and it has the appropriate <system.serviceModel> section to define the service endpoints.
I suggest you take a look at the following:
Here
WCF is about A(address) B(binding) C(contract), you need to specify binding.

Calling a web service: what am I doing wrong here?

I have the following code for consuming a service that is not working for me. Can anyone suggest what I can do to narrow down whats going wrong? I know this is vague so please tell me what you require to provide any suggestions.
The address is: http://localhost:57667/ExampleService.svc/
When visiting directly I get the 'You have created a service... message'
The code that goes wrong is here. It causes the following error:
_url = "http://localhost:57667/ExampleService.svc";
TextReader textReader = new StringReader(HttpPostClient.Post(new Uri(_url), bodyData.ToString(), _exampleServiceRequestEncoding, Properties.Settings.Default.HttpPostClientExampleAvailabilityTimeout));
ERROR MESSAGE:
When visiting this URL directly: http://localhost:57667/ExampleService.svc/ProcessRequest
The exception message is 'No component for key example.ExternalWebServiceStubs.Example.ExampleService was found'.
Castle.MicroKernel.DefaultKernel.get_Item(String key) at Castle.Facilities.WcfIntegration.WindsorInstanceProvider.GetInstance
many thanks,
The normal practice would be to create a proxy class via svcutil.exe (visual studio command prompt) or "add service reference" to consume the service, and then for you to use the methods of your proxy class to call your service's methods.
This tutorial should help (it's based on Visual Studio 2005, you didn't say what version you were using, but you should get a good grounding)
http://msdn.microsoft.com/en-us/library/bb332338.aspx#msdnwcfhc_topic6
Since troubleshooting wcf services will be lot more easier when you provide web.config element also at service side.
My general guess here is, all the wcf services by default uses wsHttpBinding which will not allow direct calling of service like an asmx service we do.
You can replace wsHttpBinding with basicHttpBinding and disable the security to your service in order to get the service work like you are expecting.
Please add some more details about ExampleService.svc binding and it will help you get this resolved fast
Hope this will help

Custom SharePoint 2010 WCF Service - How to set MaxReceivedMessageSize parameter

I have developped a custom WCF Web Service within a SharePoint 2010 Visual Studio empty project.
My web service is working well. The problem is related to the size of the request I can send to this web service. I have realized that is something around 300Kb. If I go bigger than that, the service/client is sending me an exception.
I've looked around on the web and see that the MaxReceivedMessageSize setting may be my solution. I've tried using a FeatureActivated method to set this information using this kind of request:
// increase maximum size of requests to this web service: http://msdn.microsoft.com/en-us/library/ff599489.aspx
SPWebService contentService = SPWebService.ContentService;
contentService.ClientRequestServiceSettings.MaxReceivedMessageSize = -1;
SPWcfServiceSettings csomWcfSettings = new SPWcfServiceSettings();
csomWcfSettings.MaxReceivedMessageSize = 10485760; // 10MB
contentService.WcfServiceSettings["PT-SP-P2S-DocumentCreator.svc"] = csomWcfSettings;
contentService.Update(); // access denied thrown here!
With that code, I have an Access denied (I'm actually the Site Collection Administrator).
I also know that this parameter may be set in the app.config of web service host but, in SharePoint, where to I need to change this parameter.
I think you should make this change in the web.config file of the Web Application in which the feature is activated. SharePoint provides APIs to make web.config changes. In fact, using APIs to make changes to your web.config is preferred option because SharePoint uses Timer Job and makes same updates to all Web Front End servers in your environment. There are 2 ways to make changes to web.config as described here:
http://msdn.microsoft.com/en-us/library/ms460914.aspx
In your case, since you want to make the change only when your feature is activated, you would take the API approach as documented here: http://msdn.microsoft.com/en-us/library/bb861909.aspx

Web Service method signature changed to request/response objects for datatype string[]

I have two websites, both using .Net framework 3.5. One website is hosting a soap web service and the other is referencing this service.
I'm having some unexpected happenings with my web method signatures. I have a simple method in my web service with a signature such as:
[WebMethod]
public string[] HelloWorld()
{
return new[] { "Hello World" };
}
But when I reference this web service using the 'Add Service Reference' feature in VS2008, with configuration set to "Always generate message contracts" (although when i check the 'reuse types in referenced assemblies', i seem to have the same issue), the signature seems to be changed by the auto generated proxy objects to the following:
HelloWorldResponse HelloWorld(HelloWorldRequest request)
I've tried to look this up on the net, but having trouble finding something that will simply explain to me why this is happening, and whether I can/should try to work around it?
I also have this question:
How does one determine whether they should choose the service reference configuration option to "reuse types in referenced assemblies" and "always generated message contracts"?
The message-contracts option might have this effect; the purpose here being to allow fine-grained control over the underlying request. Ultimately, what you are sending (behind the scenes) is a request payload.
The reuse-types option is more typically used with objects (not things like string[]) - and means that if you have a 100% matching Customer (say) class locally, it can re-use that for the web-service rather than generating a proxy type.
Additionally, note that you aren't actually consuming a WCF service ([WebMethod] is the older web-service style). As such you may have better results with a "Web Reference"; when adding the service, hit "Advanced", then "Add Web Reference...". This uses the older UI and wsdl.exe to generate code intended for [WebMethod] (asmx), rather than WCF (svc).
Of course, rather than hosting a [WebMethod], you could (since the server is also 3.5) host a WCF service; this may make things easier.
A final point of WCF; if you really want the same contract at client and server, you can use either assembly or class sharing to use the very same types at both end. This is not supported for [WebMethod], though.

Categories