I post this questions after lot of time reading different messages about WCF.
I have developed a WFC service that is working at an specific location.
I have developed a vb.net app that consum the WCF service mentioned. It works fine.
I have now a new choice. How can I change from the app the address of the service?. I mean, suppose the service is located at IP a.b.c.d, and now has changed to e.f.d.r. How can I change this on the app?. Should I modify the app.config of the app in execution time? should be possible? Isn't another way to change the address?
A piece of the app.config I'm using on the app is the following:
< bindings>
< basicHttpBinding>
< binding name="BasicHttpBinding_IWCF_ServicioWeb" />
< /basicHttpBinding>
< /bindings>
< client>
< endpoint address="http://localhost:49311/WCF_ServicioWeb.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IWCF_ServicioWeb"
contract="MiServicioWeb.IWCF_ServicioWeb" name="BasicHttpBinding_IWCF_ServicioWeb" />
< /client>
I hope someone could help me...
Just add an ApplicationSettings entry to your config file
<MyApp.Properties.Settings>
<setting name="MyServiceUrl" serializeAs="String">
<value>http://a.b.com/ServicioWeb.svc</value>
</setting>
</MyApp.Properties.Settings>
Now, every time you need to call the service write
Using wcf = New ServicioClient("BasicHttpBinding_IWCF_ServicioWeb",
New EndpointAddress(YourAppNameSpace.Properties.Settings.Default.MyServiceUrl))
.... call your wcf methods ....
End Using
I see that you are using basicHttpBinding. If you are not using either Transport or Message security and certificate validation is not an issue then it's just a matter of changing the Endpoint Address both on the service (server) and in the client application that is consuming the WCF service.
Related
Yet another post on http service on worker role.
Hello everyone,
I have been looking everywhere for an answer and I can't find any.
Here is the problem :
I have a worker role with a tcp entry point. It works fine locally and on azure. So far so good.
I have a windows phone app (sdk 8.0, .net 4.5) that I want to connect to this endpoint.
First problem here, the only way to access a wcf service with a windows phone project is to Right-click project, "Add service reference" and put the service address. BUT ! it doesn't work with tcp.net://{address}:{port}/{service name}.
I've searched and found that I need a http service.
All right then, I'll create a http endpoint. Code is easy, can be found everywhere.
Now here's the interesting part, I have the following error :
HTTP could not register URL http://+:8080/myservice. Your process does not have access rights to this namespace.
So I've looked it up on the internet and found 2 answers :
adding
<Runtime executionContext="elevated" />
to the ServiceDefinition.csdef file.
And setting
var binding = new BasicHttpBinding { HostNameComparisonMode = HostNameComparisonMode.Exact };
Now here's the kicker, I've done that and it still doesn't work.
Here are my Endpoints in ServiceDefinition.csdef file.
<Endpoints>
<InputEndpoint name="External" protocol="tcp" port="10100" />
<InputEndpoint name="Http" protocol="http" port="8080" />
</Endpoints>
Looking for help.
I need to connect Win8 app to WCF service. The WCF client is created using Add Service Reference.
The requirement is to change the End point URL at runtime. Win 8 does not have app.config and instead use Application Data settings.
The problem is that App needs the URL at the startup. If URL is invalid, or cannot be reached, the app is terminated.
The question is, How to manage scenarios, where configuration settings are required for app startup, and to be set up at runtime?
When you create an instance of the client, before you start using it you can change the address for the service by accessing the Endpoint property of the client. Something like the code below.
var client = new ServiceReference1.ServiceClient();
client.Endpoint.Address = new EndpointAddress(yourNewUri);
i store web service url in web.config or app.config. when i call web service like
ServiceAvailabilityTestClient.TestClient servAvailClient = new ServiceAvailabilityTestClient.TestClient();
servAvailClient.url= myapp.config url here.
servAvailClient.CallValidateCityPostalCodeZip();
the problem is the property called url is not appearing. sp please tell me what to do.
i just add wsdl file location as service reference because web service path called not being added. web service url which i try to add as web service reference is
https://devwebservices.purolator.com/EWS/V1/ServiceAvailability/ServiceAvailabilityService.asmx
1) i just not being able why i am not being able to add this web service url as service reference
2) why url property is not exposed in client side.
can anyone guide me what is the matter. thanks
You could do it through your generated client or ChannelFactory:
var client = ChannelFactory(IWcfService).CreateChannel(Binding, ServiceModel.EndpointAdress)
or
var client = New Client(binding, RemoteAdress)
EndpointAdress just takes string or uri in constructor e.g.http://yourservice.asmx
Are you using the <System.ServiceModel/> config section? If so you shouldn't have to do anything - the URL will be loaded from the <client/> section of the config when you create the channel.
How can I detect the user agent in a web service? My web service is implemented using a WCF webservice with basicHTTPBinding. It will be a post from some SOAP clients. I wish to know the user-agent from the clients.
I shall like to see some sample code for this.
I am using a WCF based web service and in the svc.cs, I tried to catch this.Context.Request.UserAgent. But it gives the following error:
this.Context.Request.UserAgent 'MySoapService.MyService' does not contain a definition for 'Context' and no extension method 'Context' accepting a first argument of type 'MySoapService.MyService' could be found (are you missing a using directive or an assembly reference?)
I also tried System.Web.HttpContext.Current.Request.UserAgent and it says:
'System.Web.HttpContext.Current' is null
Edit note:
I tried to activate the ASP.NET compatibility mode. I added <serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> in the config file and added [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] on the top of the class that implements the service interface. Then using System.Web.HttpContext.Current.Request.UserAgent gives me the user agent as desired.
There is another way to get the user agent without enabling ASP.NET compatibility in web.config:
string userAgent = WebOperationContext.Current.IncomingRequest.Headers["User-Agent"];
You can use also:
WebOperationContext.Current.IncomingRequest.UserAgent
You can read user agent from the HttpContext.Current.Request object if you enable ASP.NET compatibility in web.config:
What a totally unhelpful response!
This is not a trivial task. Yes it is obviously possible to get te user-agent string but how does one actually do it? I spent 2 hours checking google and so on but found the answer buried in MSDN documentation. In Visual Studio, from within a WebMethod try
this.Context.Request.UserAgent
That should do it!
User-Agent is a standard HTTP header. It'll be available to your web service just like it's available to anything CGI-like.
Did you even bother searching for this before posting your question? There must be millions of hits for it on Google.
I created WCF web service, deployed it, and debugged it. I wrote a console app, referenced the web service, and everything works.
Now, I'm attempting to consume the web service in a silverlight 3 application. I added the following code to a click event.
TagServiceClient client = new TagServiceClient();
Tag[] tags = client.GetTags();
client.Close();
VS is telling me it can't find the GetTags() and Close() methods. But VS has no problem with these methods in the console app.
I added a using statement for the service reference to the top of my file.
I placed a clientaccesspolicy.xml file in the root domain and in the folder containing the web service. Doesn't seem to change anything regardless where it is.
What's going on? Any suggestions? This is my first time consuming a web service in Silverlight so I may just be missing something.
You will need to generate a new client proxy to use in the Silverlight app - IOW, from the Silverlight app, add a new service reference, and point it to the service.
You will then see that things are a little different - you will find that there are async methods in the proxy, not the synchronous ones you will have seen in the proxy generated for the console app. So in the silverlight app, your code will end up looking something like this:
client.GetTagsCompleted += [my event handler];
client.GetTagsAsync();
and in your event handler:
if (e.Error == null)
if (!e.Cancelled)
List<Tag> tags = new List<Tag>(e.result);
When you add a the service reference to the silverlight app, make sure you have a poke around the advanced settings, because you can change what sort of collection the items are returned in, etc (the default return collection is an ObservableCollection<T>).
If you want to avoid this sort of thing (different proxies for different apps or modules), then consider using svcutil to generate your proxy instead of allowing VS to do it (VS doesn't use svcutil).