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>
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>
Bear with me for a moment, I want to layout the whole picture.
I have a WPF application (.exe) which needs to open and display a window when a COM object (VB6 macro) calls an application method. I've made one managed code project in the .exe solution COM visible and the VB6 macro successfully calls a method on this managed code project (COM stub).
My COM stub receives the method call and runs Process.Start on the WPF exe passing in command line arguments the first time. My application starts as expected. I now need to send data from the VB6 macro, through my COM stub and into the WPF exe on successive calls. I added a WCF project to my WPF exe solution producing a "netNamedPipeBinding" service. I've added a ServiceReference in the COM stub to talk to the WPF exe. I've tested the WCF service separately with a console application and it works. I've built the COM stub ServiceReference using the same Metadata Address as my test cases, and it constructed the reference normally.
My test driver calls the COM stub method and the WPF application starts. My next call to the COM stub tries to instantiate the service client and I get the dreaded error:
"Could not find endpoint element with name 'internal' and contract 'SelectedStudentReference.ISelectedStudent' in the ServiceModel client configuration section."
Here is the contents of my app.config in my WCF service project part of the WPF exe solution.
<system.serviceModel>
<bindings />
<client />
<services>
<service name="AwardManager.Service.SelectedStudentService">
<host>
<baseAddresses>
<!--<add baseAddress = "http://localhost:8080/SelectedStudent" />-->
<add baseAddress="net.pipe://localhost/SelectedStudent" />
</baseAddresses>
</host>
<endpoint
name="internal"
address="net.pipe://localhost/"
binding="netNamedPipeBinding"
contract="AwardManager.Service.ISelectedStudent"
/>
<endpoint
address="mex/pipes"
binding="mexNamedPipeBinding"
contract="IMetadataExchange"
/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="False"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
I've tried copying this into the WPF app.config, without success. This service works with a console app test driver. Since this is my first experience with WCF, I'm at a loss for the next troubleshooting step. I looked at another Stackflow question but couldn't figure out if it applied to my case. Any ideas?
It's always the last place you look. My console app test driver was calling the COM stub which carried the ServiceReference. I added this line of code just before the call that created the ServiceClient.
string dir = System.IO.Directory.GetCurrentDirectory();
This showed that the client was being created in the test driver directory. I copied this from my COM stub into the app.config for the test driver. Works like a champ now.
<system.serviceModel>
<bindings>
<netNamedPipeBinding>
<binding name="internal" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false"
transferMode="Buffered" transactionProtocol="OleTransactions"
hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288"
maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport protectionLevel="EncryptAndSign" />
</security>
</binding>
</netNamedPipeBinding>
</bindings>
<client>
<endpoint
address="net.pipe://localhost/"
binding="netNamedPipeBinding"
bindingConfiguration="internal"
contract="SelectedStudentReference.ISelectedStudent"
name="internal">
<identity>
<userPrincipalName value="me#xyz.com" />
</identity>
</endpoint>
</client>
</system.serviceModel>
This led to my solution: move the service ref stuff to the 'main' app.config file,then it can be found by the 'child' (wpf) project.
I've deployed a WCF service on IIS 7.
Browsing to the service from a browser shows that it's running fine.
Connecting to the service from a Silverlight application produces the following error:
The HTML document does not contain Web service discovery information.
Metadata contains a reference that cannot be resolved: 'http://localhost:81/SdkService.svc'.
Content Type application/soap+xml; charset=utf-8 was not supported by service http://localhost:81/SdkService.svc. The client and service bindings may be mismatched.
The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..
If the service is defined in the current solution, try building the solution and adding the service reference again.
The service project is complied with .Net 4.0 and the Application pool for that service is also .Net 4.0
The Silverlight client is also compiled with .Net 4.0
Here's the service web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
<system.serviceModel>
<diagnostics>
<messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
</diagnostics>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="6553600"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="false" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
</configuration>
enter code here
Silverlight only supports basicHttpBinding. I believe the WCF default is wsHttpBinding so you may need to change this and then update your service reference.
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.