I'm trying to write a cmdlet that accesses one of my wcf webservices.
I've been looking at the new cmdlet : New-WebServiceProxy, but it only really seems capable of consuming ASMX webservices.
I've seen this article; which is focussed around Powershell v1.0
I'd rather use a better method (if one exists).
http://keithhill.spaces.live.com/blog/cns!5A8D2641E0963A97!645.entry
From my other .net apps that consume this webservice, here's the sort of configuration i use;
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IMyService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536000" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="819200" maxArrayLength="1638400" maxBytesPerRead="409600" maxNameTableCharCount="1638400" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true" algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://myServer/MyService/MyService.svc" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IMyService" contract="MyService.IMyService" name="WSHttpBinding_IMyService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
Anyone wanna advise me?
Ultimately you are going to want to create a client side proxy object, compile that into a .NET assembly, create that proxy and program against it in PowerShell. New-WebServiceProxy was written to allow you to do that. I'm surprised that it would only work against ASMX services? Perhaps it isn't working for you because you don't have a MEX endpoint defined in your config file? See this article on how to create a MEX endpoint that will enable proxy generation for your web service.
Related
I'm a windows dev with very little knowledge of web applications and ASP. I'm trying to create a C# dll (which is making a webservice call) for someone, that is being called from a CLASSIC ASP app.
It all started from a WinForms test app that successfully loaded a WSDL and called that web service. Now the requirement is to take the test app functionality, move it to a dll and call that dll from the ASP app. I naively left the appconfig file there, and when that dll was called, he got this well known error:
Could not find default endpoint element that references contract Service1.MyService 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.
I understand that classic asp doesn't have config files - I read a lot of posts about it, and most of the relevant ones mention to use BasicHTTPBinding and provide an endpoint address on the fly. How do I do that? Any examples?
I saw this answer:
All I needed to do is to create a BasicHTTPBinding and provide an endpoint address on the fly.Then create a new instance of the web service using the created binding and endpoint address.
But i'm not sure how to do it.
This is the appconfig that worked for the winforms app:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IMyService">
<security mode="Transport">
<transport clientCredentialType="Certificate" proxyCredentialType="None"
realm="" />
</security>
</binding>
<binding name="BasicHttpBinding_ICustomerService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://MyService.svc"
behaviorConfiguration="custom" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IMyService" contract="MyService.IMyService"
name="BasicHttpBinding_IMyService" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="custom">
<customInspector />
</behavior>
</endpointBehaviors>
</behaviors>
<extensions>
<behaviorExtensions>
<add name="customInspector" type="CustomBehaviors.CustomBehaviorExtensionElement, CompeteDataServiceTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
</system.serviceModel>
You will need to configure the service through code, as there is no config file in this case. See Configuring WCF Services in Code.
I'm in the process of adding SSL security with Windows authentication to a formerly unsecured IIS hosted WCF service application. To my surprise, I found that two of the service endpoints were already using a Binding with Transport and Windows security. This is confusing because the client applications consuming this service are not configured to use Transport security or Windows credentials. Here is the service config:
<binding name="LargeBuffer" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
</binding>
...
<service behaviorConfiguration="WebServices.GCServiceBehavior"
name="WebServices.GCService">
<endpoint address="" binding="basicHttpBinding" name="GCSecuredEndpoint"
bindingName="largeBuffer" contract="WebServices.IGCService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
When I use Visual Studio to generate the client proxy and configuration, it creates this:
<binding name="GCSecuredEndpoint" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
...
<endpoint address="http://devservices.mysite.com/GCService/GCService.svc"
binding="basicHttpBinding" bindingConfiguration="GCSecuredEndpoint"
contract="GCSvc.IGCService" name="GCSecuredEndpoint" />
Notice it's security mode="None" and Transport ClientCredentialType is None instead of Windows. When I call a method on the GCService it succeeds. I would expect it to first complain that I'm trying to access over http instead of https, but it doesn't. Next I would expect it to not authenticate or complain that the client endpoint doesn't match the service in terms of authentication, but it doesn't.
I have another service in the same application that I had just setup with Transport/Windows security just without all the buffer/readquota stuff. For starters, when I generate the client proxy/config in VS for this service, it automatically uses the https address, transport security, and windows authentication. If I manually change it to use None for both, as above, a call to one of the service methods does not succeed, as expected. Why is the GCService above working?
The server config has
bindingName="largeBuffer"
instead of
bindingConfiguration="LargeBuffer"
The LargeBuffer binding configuration was never being used.
I'm not having any success setting up HTTPS in my development environment on an existing WCF service. The service has been fine with http. I'm using the hosts file to redirect to localhost, which has been working for http.
My web service configuration
<services>
<service name="EnfieldWebService">
<endpoint address="https://enfieldwebservice.devserver.int/EnfieldWebService.svc"
binding="basicHttpBinding" bindingConfiguration="transportSecurity" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="transportSecurity">
<security mode="Transport">
</security>
</binding>
</basicHttpBinding>
</bindings>
Client configuration
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IEnfieldWebService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://enfieldwebservice.devserver.int/EnfieldWebService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IEnfieldWebService"
contract="HttpsEnfieldService.IEnfieldWebService" name="BasicHttpBinding_IEnfieldWebService" />
</client>
And Unit Test Results:
System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at
https://enfieldwebservice.devserver.int/EnfieldWebService.svc that
could accept the message. This is often caused by an incorrect address
or SOAP action. See InnerException, if present, for more details. --->
System.Net.WebException: The remote server returned an error: (404)
Not Found.
Used WCF Configuration Editor to rewrite essentially the same configuration. All that it removed was
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
Turns out this feature is only compatible with http, and breaks https.
I'm using WCF to connect to a remote web service (asmx) for testing at this point. The remote web service is unsecured for now (no https, no user name, password). I can add the WCF service reference, and all the classes are generated ok. When I make the call to the webservice, it just hangs.
So I can connect with the SOAP UI tool and return data just fine. I'm thinking it is something wrong with my binding. Anyone see anything I'm missing?
<system.serviceModel>
<bindings>
<!-- Need to change some settings here for HTTPS and Basic Auth when those go online-->
<basicHttpBinding>
<binding name="ServiceSoap" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false"
bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://<snip>/Service.asmx"
binding="basicHttpBinding" bindingConfiguration="ServiceSoap"
contract="PRIOrderService.ServiceSoap" name="ServiceSoap" />
</client>
</system.serviceModel>
Requesting the wsdl endpoint does not trigger a creation of the instance of your service. If you are using a custom service host factory look at that, otherwise look at the constructor of your service implementation or debug the service method itself.
I have build an APi which is a WCF Service. In the web.config for the service i have specified a custom bindong looking like this:
<bindings>
<wsHttpBinding>
<binding name="FxBinding"
maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647"
closeTimeout="00:20:00"
openTimeout="00:20:00"
receiveTimeout="00:20:00"
sendTimeout="00:20:00"
messageEncoding="Mtom">
<readerQuotas
maxDepth="64"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="4096"
maxNameTableCharCount="16384" />
<security mode="None"></security>
</binding>
</wsHttpBinding>
</bindings>
Telling the configuration to use the binding i have specified by setting the "name" attribute in the endpoint tag:
<services>
<service name="Dba.Admanager.Api.ListingServiceContract" behaviorConfiguration="Dba.Admanager.Api.ListingServiceContractBehavior">
<endpoint address="" binding="wsHttpBinding" name="FxBinding" contract="Dba.Admanager.ApplicationController.Api.IListingServiceContract">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
See. When i create an web reference to the service in VS2008 a app.config are generated.
In this app.config the binding used, should be the one specified above. But in the app.config is a default binding with default values in the "maxArrayLength" for instance.
<bindings>
<wsHttpBinding>
<binding name="FxBinding" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="">
<extendedProtectionPolicy policyEnforcement="Never" />
</transport>
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://l-aar-00424012.corp.ebay.com/Admanager.Api/ListingServiceContract.svc"
binding="wsHttpBinding" bindingConfiguration="FxBinding" contract="WCFListingServiceContract.IListingServiceContract"
name="FxBinding">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
I can see that the client is using the FxBinding configuration, but why on earth all the values are default, i dont understand. Can anubody give at at clue on how to customize the binding-values and make it reflect on the "client"-part?
If i change the values manualle in the app.config i get the desired effect, but every time the webreference is updated, VS just adds a new binding with the default values.
Information such as maxArrayLength is not part of the WSDL, so the client cannot infer it and just takes default values.
As Darin already mentioned - since those binding parameters aren't part of the interoperable metadata between service and client, they can't be automagically picked up by the client when you create a new client proxy.
What you could do is this:
define your binding configurations in a separate config file and reference that on the server - i.e. put everything inside <bindings> into bindings.config and then reference it from your server side web.config or app.config:
<system.serviceModel>
<bindings configSource="bindings.config" />
</system.serviceModel>
Then copy that bindings.config to your client side and do the same thing there in your app.config.
Note: yes, Visual Studio will complain about the "configSource" not being defined and all - but that's just a flaw in the VS intellisense for config files. Trust me - it works - I use it everyday in production systems! Every configuration section in .NET has a "configSource" attribute!
With this method, you create one file that contains those binding configurations for your system and you can use it on both the server and the client side.