I want to make a simple WCF Hello world client which could connect to a WCF REST service.
But I've got the following error:
"Could not find default endpoint element that references contract 'ServiceReference1.IService1' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element."
What I did:
-I created a new project called "WCFerror" with the "WCF Service Application" template
-My web.config is like this: http://pastebin.com/KEGqRgPr
-My service interface is also simple:
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebGet(UriTemplate = "GetData?value={value}", ResponseFormat = WebMessageFormat.Json)]
string GetData(int value);
}
-I created a new Console Application.
-I started a new instance of my WCFerror service (via "Start Debugging"), it is hosted, I tried it out in a web browser
( like: http://localhost:58475/Service1.svc/GetData?value=4 ), it worked fine.
-Then I added a service reference to the Console Application (the address was: http://localhost:58475/Service1.svc) and in the background, the svcutil generated the Client code, and an app.config - but an empty app.config!
-So my client not works:
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
Console.WriteLine(client.GetData(4));
-I tried to run the svcutil via the command prompt like this:
svcutil.exe /language:cs /out:GeneratedProxy.cs /config:app.config http://localhost:58475/Service1.svc
But it generates the same empty app.config.
What did I do wrong? :(
Add Service Reference uses WSDL or WS-MetadataExchange. Both of these are SOAP constructs. REST does not have a metadata standard. You will have to roll the messages yourself, preferably using a framework. Have you looked at HttpClient that is part of the new Web API? Its available via Nuget
Related
Is there any way to configure WCF Service Reference from configuration file? I would like to configure WCF service reference with such settings as SecurityMode, Address, ReaderQuotas etc. I would also like to be able to choose between WsHttpBinding, BasicHttpBinding, BasicHttpsBinging etc (like normal configuration provided by app.config in .NET Framework).
Is there any way to achive that in .NET Core/.NET Standard?
Thank, Bartek
Certain binding, such as Wshttpbinding,Netnamedbinding is not compatible with DotNet Core framework. Consequently, we could not configure it. However, this doesn’t represent that we can’t configure Basichttpbinding, Nettcpbinding.
At present, the WCF service cannot be created by using DotNet Core without using the third-party library. Moreover, WCF client based on DotNet Core just a compatible workaround.
https://github.com/dotnet/wcf
Like the DotNet Framework project, Microsoft Corporation provides Microsoft WCF Web Service Reference Provider tool to generate a client proxy.
https://learn.microsoft.com/en-us/dotnet/core/additional-tools/wcf-web-service-reference-guide
After adding connected service, it shall generate a new namespace contains the client proxy class. Most of the client configuration located in the Reference.cs.
Also, we could manually program the code to call the WCF service.
class Program
{
static void Main(string[] args)
{
//using the automatically generated client proxy lcoated in the Reference.cs file to call the service.
//ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient();
//var result = client.TestAsync();
//Console.WriteLine(result.Result);
//using the Channel Factory to call the service.
Uri uri = new Uri("http://10.157.13.69:21012");
BasicHttpBinding binding = new BasicHttpBinding();
ChannelFactory<IService> factory = new ChannelFactory<IService>(binding, new EndpointAddress(uri));
IService service = factory.CreateChannel();
var result = service.Test();
Console.WriteLine(result);
}
}
[ServiceContract]
public interface IService
{
[OperationContract]
string Test();
}
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-use-the-channelfactory
Feel free to let me know if there is anything I can help with.
I have problems with writing Java client for wshttpbinding web service.
I wsimport-ed .wsdl and i try to
TestService iface = new TestService();
ITestService implmt = iface.getWSHttpBindingITestService();
then i call web service method set
implmt.set("s", 1);
And i get
Exception in thread "main" javax.xml.ws.WebServiceException:
java.net.SocketException: Connection reset
I cannot change server side, it must be as is. So change to basicHttpBinding is not possible (if i change it i don't have any problem but alas)
Client must be made in Java.
Oh ok I solved it. I imported METRO .jar files to build path and moved them to top (to be first)
It is crucial to place those jars on top.
I've created a REST web service that I need to consume from within an asp.net app. The service is hosted from a console window. I can get it running fine, and I can get output from it as well when surfing to it in a web browser. The problem is, when I try to "Add Service Reference" from my asp.net app, it complains of various things depending on which service URL I point it at. End result is I cannot figure out how to add the service reference.
My Interface is defined like so:
[ServiceContract]
public interface IWave {
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "/devices")]
List<Device> getDevices();
...
}
Here's how I'm hosting my service:
// Port is 1178
var endPoint = new EndpointAddress(string.Format("http://localhost:{0}/wave", port));
var waveServiceSingleton = new WaveSVC();
binding = new WebHttpBinding();
var behavior = new WebHttpBehavior();
behavior.FaultExceptionEnabled = true;
host = new WebServiceHost(waveServiceSingleton, endPoint.Uri);
// Get the service debug behavior and tell it to include details about errors
ServiceDebugBehavior sdb;
sdb = host.Description.Behaviors.Find<ServiceDebugBehavior>();
sdb.IncludeExceptionDetailInFaults = true;
host.AddServiceEndpoint(typeof(IWave), binding, "");
// Add mex endpoint
ServiceMetadataBehavior mexBehavior = new ServiceMetadataBehavior();
mexBehavior.HttpGetEnabled = true;
host.Description.Behaviors.Add(mexBehavior);
host.AddServiceEndpoint(typeof(IWave), MetadataExchangeBindings.CreateMexHttpBinding(), endPoint.Uri.AbsoluteUri + "/mex");
host.Open();
When I browse to http://localhost:1180/wave/devices, I see a json string in the body of my browser. This is expected and works as desired. I cannot point my "Add Service Reference" wizard to this URL, as it complains that:
The document at the url http://localhost:1178/wave/devices was not recognized as a known document type.
The error message from each known type may help you fix the problem:
- Report from 'XML Schema' is 'Data at the root level is invalid. Line 1, position 1.'.
- Report from 'DISCO Document' is 'Data at the root level is invalid. Line 1, position 1.'.
- Report from 'WSDL Document' is 'There is an error in XML document (1, 1).'.
- Data at the root level is invalid. Line 1, position 1.
Metadata contains a reference that cannot be resolved: 'http://localhost:1178/wave/devices'.
The remote server returned an unexpected response: (405) Method Not Allowed.
The remote server returned an error: (405) Method Not Allowed.
If the service is defined in the current solution, try building the solution and adding the service reference again.
I have a nagging suspicion that I need to point my "Add Service Reference" to the mex, but that doesn't work either and indeed, when I browse to the mex address of http://localhost:1178/wave/mex, I get a blank page.
EDIT 1
Just to eliminate JSON being the culprit, I changed my contract to output Xml instead of Json. The result was the same: I can't add a service reference using this URL: http://localhost:1178/zwave/devices/xml (even though that URL produces XML).
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Xml, UriTemplate= "/devices/xml")]
Thanks in advance for any help provided.
Traditionally, the "add web reference" option you are using in Visual Studio is meant for referencing XML Web Services only. Your service is defined in terms of rest/json and not in terms of soap/xml/wsdl that visual studio expects.
I suspect that Visual Studio simply isn't able to generate proxies for a json/rest service as yours. This is confirmed in the documentation on the WCF rest starter kit for .NET 3.5 (see the section "Consuming RESTful Services with HttpClient", search for "not possible to generate strongly-typed proxies like you’re used to with SOAP").
I'm not sure whether it is still unsupported in VS2010 / .NET 4.0, but I think you have to look for another option than "add web reference".
Perhaps found for the blank page:
Replace
host = new WebServiceHost(waveServiceSingleton, endPoint.Uri);
with
host = new ServiceHost(waveServiceSingleton, endPoint.Uri);
this worked for me
I would like to build an app in C# that connects to an Apache AXIS web service and performs the following operations via SOAP.
Login in to the server.
POST string data to server
Receive and display server response
Here's the tough part. I do not have access to the server, nor do I know where the .JWS file is located on the server. I was able to get to the WSDL file in my web browser, so I know a "Login" operation exists as well as an operation to take in data.
I have tried accessing the web service via URL, but I keep getting this message:
Hi there, this is an AXIS service!
Perhaps there will be a form for
invoking the service here...
In summary, is there anyway I can connect to this web service when all I have is the URL of the WSDL file? Are web services accessible via URL?
Thank you
Use WCF, and generate client proxies to the web service using the svcutil.exe tool.
running svcutil.exe http://url.to/webservice?WSDL the_wsdl.wsdl /language:C# should generate proxy classes you can use in your C# project, and you'd call the service e.g. like
BasicHttpBinding myBinding = new BasicHttpBinding(); //might not even need these
// 2 lines if you ran svcutil.exe directly on the web service URL
EndpointAddress myEndpoint = new EndpointAddress("http://url.to/webservice");
TestClient client = new TestClient(myBinding,myEndpoint); //the generated classes
// svcutil.exe created
client.SomeOperation(42); // call an SomeOperation of the web service
Thanks for everyone's help. Looking back on this question, I can see how severely confused I was. Here is the solution I followed.
Assuming you know the URL of the WSDL file of the service you wish to connect to then just do the following.
Boot up Visual Studio
On the top toolbar navigate to Data -> Add New Data Source then choose Service in the new dialog
In the address bar, enter the URL of the wsdl file (EXAMPLE: http://server.com/services/displayName?wsdl)
Near the bottom of the dialog, change the namespace to something relevant to the project (EXAMPLE: sampleService)
Now Visual Studio should compile the client proxies for you that you can use to access the web services on your server. To access one of the services, all you need to do is create a new object from the class.
//Example
sampleService.ClassName test = new sampleService.ClassName();
test.displayName("Jack");
See http://msdn.microsoft.com/en-us/library/bb552364.aspx for a starting point
I've written a WCF service and hosted in IIS 6.0. When i try to create the proxy using the following command
svcutil.exe /language:cs /out:MyProxy.cs /config:app.config /a http://serviceurl
it is creating its own class name in MyProxy.cs. Why is that?
I was trying to step in to the service for debugging and i was not able to get the breakpoint hit during debugging. Could this be because i renamed the class name which is created by the Proxy?
In the service, the class name that implements the service contract is something like MyService. But in the proxy file i'm getting as MyClient.
Why is that?
Thank you
NLV
The MyClient class generated by svcutil and implementing the service contract should be used to invoke the service. It's just a client proxy. If you want to debug the service you should run the service in Debug mode and place a breakpoint there.