troubles with generating a service reference - wcf

I have to build a .Net application that consumes a bunch of web service. This web service runs under weblogic. The WSDL of the web services mention a XSD file that describes the types.
When I try to add a "Service reference" with VS studio, I have some errors :
Warning 1 Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.XmlSerializerMessageContractImporter
Error: Schema with target namespace 'http://mycustomer/ws/types' could not be found.
XPath to Error Source: //wsdl:definitions[#targetNamespace='http://mycustomer/ws/wsdl']/wsdl:portType[#name='lbWebPT'] C:\Projects\mycustomerproject\Service References\ClientService\Reference.svcmap
X3 for the portType, Binding and port elements of the wsdl file.
I was guessing this was because of the missing types defined in the xsd file. To workaround this error, and also to avoid duplicate code, I run the following command on my xsd file (in a pre-build event command line) :
"%ProgramFiles%\Microsoft SDKs\Windows\v7.0A\bin\xsd.exe" "$(ProjectDir)xsdofmycustomer.xsd" /namespace:"MyCustomer.WebServices.Types" /c /o:"$(ProjectDir)."
this command successfully produces a code file with the types and with the correct namespace defined in the XmlRootAttribute.
this code has been put a dedicated VS project. The project where I'm trying to reference the service reference this project. However, the error is still occurring.
What can I do to solve my problem ?
PS: I was able to partially solve my problem using svcutil.exe pathtowsdl pathtoxsd, but I'd like to be able to maintain the reference in VS for ease of use.
thx

I'm not a fan of using project Service References because of the cruft the proxy generator inserts by default. But, if you really want to use Service References for your project then you need to merge the contents of the wsdl & xsd files into a single file. The Service Reference UI assumes all the data it needs to generate the proxy is in the file you give it. SvcUtil is more flexible as you found out. You should able to replace the wsdl:import element with a wsdl:types element that contains the xsd file contents (without the xml directive of course). Next, you enter the path to the file in the address textbox of the Add Service Reference dialog and you should be good to go with Visual Studio catered proxy goodness.

Related

Reference VB.NET DLL in Kofax Document Validation Script

We are working on a validation script for Kofax Capture 9.0 / 10.0 in VB.NET 3.5.
We know how to create a script using the Admin Module, and how to get it operational.
The problem is that we need to reference a dll, located on a remote machine. (GAC is no option) This dll holds abstract classes we need in each validation script.
Even when putting the dlls locally (copy local), the Validation Module (index.exe) immediately throws the "cannot find reference" exception, even though the project compiled perfectly.
I guess the basic question comes down to: where do we put the dlls, in order for the Validation Module to find them?
The simple answer is to put the dll in the same folder as the application because this is one of the places which .NET will probe when trying to find it. The Validation module is run from the Capture bin directory which will be something like "C:\Program Files (x86)\Kofax\CaptureSS\ServLib\Bin\". This would need to be done on each client using Validation.
If you have a more complicated scenario, you could look implementing the AppDomain.AssemblyResolve Event and using Assembly.LoadFile to get the assembly from a custom location, but the using the bin path is less complicated.
If you end up having further trouble, you can troubleshoot by using the Assembly Binding Log Viewer (Fuslogvw.exe) which can tell you more details about why the assembly failed to load and where .NET tried to search for it. Assembly loading can fail for reasons other than just the path.
For more detail on how .NET loads assemblies, see the following:
How the Runtime Locates Assemblies
Locating the Assembly through Codebases or Probing
We found a solution: add all library files as "links" to the project. (Add --> Existing File --> small arrow next to "Add" --> Add as Link)
This ensures the files are compiled when you build the project. The Kofax Validation Module can now find the files, whereas when referencing the file, it could not. Why it could not, remains a mystery...

No Class files being generated from Adding a Reference to Web Service

I'm integrated our website with a 3rd party site and using their web service to authenticate. I'm using Visual Studio 2010 with Visual Basic and I'm able to use the URL they gave me to add a web reference using:
website -> add web reference -> URL -> Go -> add reference
However, after I do this there aren't any class files generated in my file structure to reference?
The files generated are:
.discomap
.disco
.wsdl
.xsd
.wsdl
.xsd
.xsd
I don't know if it is relevant, but the webservice was made using visual studio 2008.
Every tutorial I have read online has said that class files should be generated after the reference is successfully added. Am I just reading things wrong or is something else amuck?
Thanks!
I ended up having to generate the class file from the Visual Studio command line. The same link that I used to Add Web Reference was the link needed for the command line text.
This generated two files, a class file and an output.config file. I had to combine the output.config file with my web.config file and then the webservice was called correctly.

add more than one service reference for one application

I am unable to add more than one service reference to same class.
using testApp.ServiceReference1;
using testApp.ServiceReference2;
but ServiceReference2 cannot be used as namespace here
Is it possible or not??
Open the reference.cs file under the ServiceReference2 folder (Show All Files in visual studio). The namespace for the generated types will be in that file.

Build Error Ambiguous Reference WCF

I am created a wcf service. Everything has been working fine. Now all of a sudden with adding any logic I am getting a build error where I am consuming the wcf service saying:
I have an Ambiguous Reference.
I can fix this by qualifiing the object as part of the service and it works fine
ServiceReference1.AccountCredit=GetSomeData()
The thing is all thee other objects on the page are referencing an objectModel dll except this one.
I went further and viewed the service reference itself in the browser and see visual studio for whatever reason on this particular object added a file containing the following:
<?xml version="1.0" encoding="utf-8" ?>
- <!--
This file is automatically generated by Visual Studio .Net. It is
used to store generic object data source configuration information.
Renaming the file extension or editing the content of this file may
cause the file to be unrecognizable by the program.
-->
- <GenericObjectDataSource DisplayName="AccountCredit" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<TypeInfo>TestMethods.ServiceReference1.AccountCredit, Service References.ServiceReference1.Reference.cs, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
</GenericObjectDataSource>
All the other objects I use dont have this and in turn this is the only object on the client that is complaining.
It may be that "MyObject" is the only name that is present in two different namespaces, where both the namespaces are referenced by a using statement at the top of the cs file.

WcfSvcHost.exe not running when I debug a Wcf Library

I have WCF library project which I have recently done some minor refactoring on eg changing the namespace and changing it location on disk. I also removed the app.config, because I thought the app.config is used by whatever hosts the wcf service.
I have since noticed that I can no longer debug the library using the WcfSvcHost like I used to be able to do. The message I get from Visual Studio is:
'A project with an Output Type of Class Library cannot be started directly.
In order to debug this project, add ana executable project to this solution which references the library project. Set the executable as the startup orject.
I don't want to do as it says, because I didn't need to do this before. Please let me know how to restore the ability to debug it using the WcfSvcHost. On the Debug tab of the project settings, the Command line arguments is still set to: /client:"WcfTestClient.exe"
Not sure what else to try, thanks.
I have observed that changing the output path of the project cause this behavior. To re-enable the debugging using WCFSvcHost/WCFServiceClient leave the output path to default and it should work.
If you changed the project output path you can still run it, you just need to provide some extra parameters to WcfSvcHost like this (enter this in Command Line Arguments in project's debug settings):
/service:ServiceInterface.dll /config:application.config /client:"WcfTestClient.exe"
No need to enter the full path as it will be run from your new project output path
If you still get the 'A project with an Output Type of Class Library cannot be started directly' then you can try changing the start action to 'Start external program' and select the WcfSvcHost.exe in there
You need to build the project in Debug Mode in order to use WcfTestClient and WcfSvcHost
In Debug mode you don't need another project. The Wcf Service Library runs in WcfSvcHost
However if your solution has only Wcf Service Library you need the app.config to configure the endpoints and etc...