I have created a plugin dll, which is being referred by third party application. My plugin refers to a webservice endpoint. When i deploy the plugin, i should be able to point to manually edit the end point address without rebuilding the dll. Just like how the exe will pick up change when its config file is edited.
Thanks
Service endpoints and other configuration-related things should be stored in application configuration files.
These files are deployed together with the application binaries and might be changed at any time, without requiring recompliation.
Typical app.config file containing some service references:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<client>
<endpoint address="http://MyServer/MyApplication/MyService.svc"
binding="basicHttpBinding" bindingConfiguration="ServiceSoap1"
contract="IMyService" name="MyServiceSoap" />
</client>
<bindings>
<!-- service bindings configuration -->
</bindings>
</system.serviceModel>
</configuration>
For further instructions, refer to the linked MSDN article.
Related
my team is developing a silverlight application and we are now switching our solution to https on our server but we would like to use http locally. So, in the XAP file that results when building the app there is a ServiceReferences.ClientConfig having the configuration for the web services that are referenced in the project. The issue is that I would like to have some configuration when I am running it locally and have some other configuration when I deploy it. We decided to alter the ServiceReferences.ClientConfig before building because otherwise it would be encapsulated in the .xap file. We are using msbuild in a bat file to deploy the solution.
The config file:
<configuration>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="CustomBinaryBinding">
<binaryMessageEncoding />
<httpTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="../../PlatformAdminUtil.svc"
binding="customBinding" bindingConfiguration="CustomBinaryBinding"
contract="PlatformAdminUtil.PlatformAdminUtil" name="CustomBinding_PlatformAdminUtil" />
</client>
</system.serviceModel>
</configuration>
I wish to change the <httpTransport/> tag into <httpsTransport/>.
I'm new on scripting in bat files so I need some help on the script that would manage this.
I have hosted my Wcf services in a windows services, i am able to use it without any issue in my test console application, but when i try using the same service by using service reference in my silverlight application, it is giving me error.
ServiceReferences.ClientConfig has this entry:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<netTcpBinding>
...
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:8732/myservices/myservice/"
binding="netTcpBinding" bindingConfiguration="NetTcpBinding_myservice"
contract="ServiceReference1.myservice" name="NetTcpBinding_myservice">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
I am getting this error:
Unrecognized element 'netTcpBinding' in service reference configuration. Note that only a subset of the Windows Communication Foundation configuration functionality is available in Silverlight.
Will appreciate your help..
Alpee
Have you Installed WCF Non-HTTP Activation on your IIS?
Found this rather good article on using NetTcpBinding with WCF and Silverlight: http://www.codeproject.com/Articles/311250/NetTcpBinding-Configurations-for-WCF-and-Silverlig
The other thing I noted is that apparently you can't specify security options with Silverlight and netTcp, so have to specify an insecure binding (from that same example):
<bindings>
<netTcpBinding>
<binding name="InsecureTcp" receiveTimeout="Infinite">
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
Our Team is building a C# project with a Silverlight module. We deploy to a Windows 2008 with IIS 7. I’m trying to Programmatically Expire the HTTP Response Headers Associated with a Folder called ClientBin immediately. I know how to do it manually through IIS Manager. ( Basically, I go to the HTTP Response Headers Section of the folder or file that is of interest, and then I use "Set Common Headers...." to expire immediately.) However, we will be Redeploying to IIS a number of times, and I want to ensure that it is programmatically done because it’s a headache to keep Reconfiguring all the time.
Should I do it from the C# code of my project or is it better practice to do it using WMI scripting?
#kev and #jeff-cuscutis have provided the ways to configure expiration of the HTTP Response Headers using XML configuration in the web.config file of a ASP.NET application
How to configure static content cache per folder and extension in IIS7?
ou can set specific cache-headers for a whole folder in either your root web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- Note the use of the 'location' tag to specify which
folder this applies to-->
<location path="images">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:00:15" />
</staticContent>
</system.webServer>
</location>
</configuration>
Or you can specify these in a web.config file in the content folder:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="00:00:15" />
</staticContent>
</system.webServer>
</configuration>
I'm not aware of a built in mechanism to target specific file types.
You can do it on a per file basis. Use the path attribute to include the filename
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<location path="YourFileNameHere.xml">
<system.webServer>
<staticContent>
<clientCache cacheControlMode="DisableCache" />
</staticContent>
</system.webServer>
</location>
</configuration>
Our Silverlight Application can run in both http and https (SSL, using Transport Security) Mode. In our ServiceReferences.ClientConfig file we simply configured our Service Endpoint this way:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="DefaultEndpoint"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
<!-- Enable for SSL: mode="Transport" -->
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="/services/DefaultService.svc"
binding="basicHttpBinding"
bindingConfiguration="DefaultEndpoint"
contract="OurNamespace.IOurContractAsync"
name="DefaultEndpoint" />
</client>
</system.serviceModel>
</configuration>
The configured Endpoint can be accessed in both Modes. It simply depends in which context the XAP file was loaded: From http://example.com/slpage.html or https://example.com/slpage.html. Unfortunately, we have to manually switch the Security Mode setting between "None" and "Transport". Everything else would already work as desired. When Security Mode is "None" and we access via https, we get an Exception that "..https was provided but http was expected..." and vice versa. Any chance to let Silverlight automatically decide which Security Mode should be used? What is the simplest solution to this problem?
Thanks in advance
Thomas
we finally ended up with the following solution (not exactly what Valentin suggested, but +1 for help!):
The ServiceReferences.ClientConfig contains both binding and endpoint configurations like this:
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="DefaultBinding"
maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
<customBinding>
<binding name="SecureBinding">
<textMessageEncoding messageVersion="Soap12WSAddressing10" />
<httpsTransport maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="/services/DefaultService.svc"
binding="basicHttpBinding"
bindingConfiguration="DefaultBinding"
contract="OurNamespace.IOurContractAsync"
name="DefaultEndpoint" />
<endpoint address="/services/DefaultService.svc"
binding="customBinding"
bindingConfiguration="SecureBinding"
contract="OurNamespace.IOurContractAsync"
name="SecureEndpoint" />
</client>
</system.serviceModel>
</configuration>
On initialization, we read the App.Current.Host.Source.Scheme Property. The Service client is generated by the ChannelFactory, the code is similar to this snippet:
protected string EndpointName {
get {
return (App.Current.Host.Source.Scheme == "https") ?
"SecureEndpoint" : "DefaultEndpoint";
}
}
protected IOurContractAsync CreateInterface() {
var channelFactory = ChannelFactory<IOurContractAsync>(EndpointName);
return channelFactory.CreateChannel();
}
Hope this helps!
Best regards,
Thomas
I think there can be a number of ways one is to provide initparams to SL app from your web pages like
param name="initParams"
value="Https=true"
for https page
and false for html page. parse it
inside SL and set up security mode for
endpoint.
You can create/edit endpoint proxy programmatically in your SL app.
Another way could be setting transport behaviour based on link inside SL app without initparams (if begins with https ->transport else none) I believe once sl app is downloaded link should be not relative and this should be a working solution.
You can make a factory method to create service proxy and put this setup proxy logic inside it , which would be simpler than completely removing this serviceconfig file.
You would simply call
MyServiceClient client = Factory.MakeClient()
and I think its an elegant enough solution. in MakeClient you decide what transport security to use and its done.
I have a problem with a my Web service and i need help.
I have a Silverlight project and the ASP part Silverlight.Web. In Silverlight.Web a added a Linq to SQL file, a database userd to validate user login, and a created a service, a asmx file. In Silverlight project a added a Service Reference for my asmx Web Service. After build the ServiceReferences.ClientConfig was created. Whwn i run my project the service is not working with the created ServiceReferences.ClientConfig file:
If i comment this part
will work only if run my project from VisualStudio,but if publish my project on IIS, the service is not working.(i change in ServiceReferences.ClientConfig my service path http://localhost/silverlight/UserLogin.asmx, where my service is published) I get this error:
Error: Unhandled Error in Silverlight Application An exception occurred during the operation, making the result invalid. Check InnerException for exception details. at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
at SilverlightPowerPoint.UserLoginService.UsersLoginCompletedEventArgs.get_Result()
at SilverlightPowerPoint.Login.uls_UsersLoginCompleted(Object sender, UsersLoginCompletedEventArgs e)
at SilverlightPowerPoint.UserLoginService.UserLoginSoapClient.OnUsersLoginCompleted(Object state)
Source file: http://localhost/Silverlight/SilverlightPowerPointTestPage.aspx
If i run the service from my IIS http://localhost/Silverlight/UserLogin.asmx, i give the parameters and it works, it return me the answer.
What can i do?
Thanck you,
Andrei
ServiceReferences.ClientConfig file:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="UserLoginSoap" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<security>
<transport>
<extendedProtectionPolicy policyEnforcement="Never" />
</transport>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:50470/UserLogin.asmx"
binding="basicHttpBinding" bindingConfiguration="UserLoginSoap"
contract="UserLoginService.UserLoginSoap" name="UserLoginSoap" />
</client>
</system.serviceModel>
It works after i comment this:
<security>
<transport>
<extendedProtectionPolicy policyEnforcement="Never" />
</transport>
</security>