RateService not defined with FedEx WSDL in VB.NET - vb.net

I am using using VB.NET in Visual Studio 2007. I am trying to integrate the FexEd rating service into one of my company's websites using the FedEx WSDL. My connection/integration with the WSDL seems to be working properly as far as I can tell (first time working with WSDLs) since it isn't complaining about undefined methods and such.
The exception to this is that when I try to create a new instance of RateService I get an error
"Type 'Rate Service' is not defined."
I am using the exact same declaration that is in the sample code that FexEx provides Dim service As RateService = New RateService() and have the same import statements.
Can anybody think of a reason why I am having problems with just this one class? Or is there anybody who has used the Fedex service that can give me pointers? Feel free to ask me questions if you need more info since I most likely left out something important.
Thanks in advance.
Here is the beginning of the RateService Constructor asked for by urbanlemur
Imports System.ComponentModel
Imports System.Diagnostics
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Serialization
'
' This source code was auto-generated by wsdl, Version=2.0.50727.1432.
'
''' <remarks/>
<System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl", "2.0.50727.1432")> _
<System.Diagnostics.DebuggerStepThroughAttribute> _
<System.ComponentModel.DesignerCategoryAttribute("code")> _
<System.Web.Services.WebServiceBindingAttribute(Name := "RateServiceSoapBinding", [Namespace] := "http://fedex.com/ws/rate/v13")> _
Public Partial Class RateService
Inherits System.Web.Services.Protocols.SoapHttpClientProtocol
Private getRatesOperationCompleted As System.Threading.SendOrPostCallback
''' <remarks/>
Public Sub New()

Just to verify did you create the proxy class? (Sounds like you did but never hurts to ask)
Create web service proxy in Visual Studio from a WSDL file
Do you have the connection defined in your web config?
<applicationSettings>
<RateWebServiceClient.Properties.Settings>
<setting name="RateWebServiceClient_RateServiceWebReference_RateService" serializeAs="String">
<value>##fedex webservice address ##</value>
</setting>
</RateWebServiceClient.Properties.Settings>
</applicationSettings>

Related

CreateObject("...") in VBScript fails to create a VB.Net class library com object (Windows Server 2000)

I am writing a application using ASP and VBScript. There a library I can only find one written for .Net application. So I tried to create a class library wrapper and compiled it to a DLL using VB.Net (Microsoft Visual Basic 2010 Express).
The DLL works in my own desktop (Windows 7) but it fails in the server (Server 2000).
Error message is "System cannot find the file specified"
Server config
OS: Microsoft Windows 2000 Server (SP4)
.Net framework installed: v2.0.50727
The code I wrote in my testing project is simply a class doing nothing.
Imports System.IO
Imports System
<ComClass(Object1.ClassId, Object1.InterfaceId, Object1.EventsId)> _
Public Class Object1
#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String = "f5dcfb08-7a83-4501-bd89-03e38cad819c"
Public Const InterfaceId As String = "8a313e0b-60e5-4ff4-8a7d-e7b1582eec71"
Public Const EventsId As String = "fe55f7d8-691f-4c76-968a-37019fa9bb53"
#End Region
' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
Public Sub New()
MyBase.New()
End Sub
Public Sub Hello()
'...
End Sub
End Class
What I did :
Chose ".NET Framework 2.0" in Compile options
Compile it on my own desktop
Copied all file from the Bin\Release directly to a folder on the server.
Successfully registered the DLL on the server using Regasm.exe
but Object1 cannot be created using neither VB6 or VBScript.
Here is the script I used in a VBScript:
Option Explicit
Dim TestObject
Set TestObject = CreateObject("TestComObject.Object1")
Any help will be appreciated!
Alex
Go through the following check-list:
1) Make sure you compile your assembly as 32-bit (in the VB.NET project settings)
2) Give your assembly a strong name (http://msdn.microsoft.com/en-us/library/xc31ft41.aspx).
You can probably configure this in your VB.NET project settings as well.
3) Use RegAsm for .NET 2.0 (C:\Windows\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe)
4) Call RegAsm with "/codebase" switch
5) Before testing with ASP, try running your test script from command line with WScript.exe.

Type being passed through web service not being recognized by consuming code

I am creating an XML web service that passes an array of custom types. In my consuming code I am referencing the code as a web reference which I have given the namespace MYWS. Now in code I am trying to assign the results of my web service call to an array of my type like so :
'instance to make a call to my web service
Dim srv As New MYDWS.ServiceNameWSSoapClient
'array to hold the results
Dim arr() As MyClass
'assign the web service call results
arr = srv.myWebMethod()
When I do this the complier complains, saying:
Value of 1 dimensional array of my.namespace.MyClass cannot be
converted to 1 dimensional array of my.namespace.MYWS.MyClass because
my.namespace.MYSW.MyClass is not derived from my.namespace.MyClass
Now I understand the message, the thing is they are the same class. The class is declared in my calling code by the web service references a dll from that project. How do I tell the compiler that these are the same type? Any help would be very much appreciated. Thanks!
The upshot is that you have a namespace mismatch. If you right-click on MyClass in your example and select Go To Definition, where does it take you? I suspect that you may end up in a locally defined class.
The solution is to change
Dim arr() As MyClass
to
Dim arr() As MYWS.MyClass
Update based on information in comments
The problem with using the web service is that you cannot cast it to a local class.
You have a couple of options depending on exactly what you need out of the local class.
If you only need methods to act on the data in the class or you need additional properties, you can create a partial class in your environment that extends the class created by the web service. For example:
Namespace MYWS
Public Partial Class MyClass
Public Property SomeAdditionalData As String
Public Sub SomeMethod
' Perform some operations on the class members
End Sub
End Class
End Namespace
However, if you have calculations or other work embedded in the class, then you will need to get the data using the web service class, then copy the data from that class into your local class. If the properties have the same names, you could ease this task using reflection.
As another option, if you have control over the web service, you could change it to a WCF service. This will allow you to reuse the exact same class code on both ends of the communication pipe.
Found a solution to the problem. In the web.config I found this:
<add key="net.mydom.mydom" value="http://localhost:7452/dir/mysvc.asmx"/>
which was what the system automatically entered when I registered the web service. I got the error messages on screen, but everything compiled and ran w/o problem.
When I manually changed to this:
<add key="net.mydom" value="http://localhost:7452/dir/mysvc.asmx"/>
The error messages went away and everything continued to function as expected.
(That only took my 7 years to figure out...)
UPDATE:
Well, not quite the fix, but it must be close. After awhile, the problem came back, when I switched back to to:
<add key="net.mydom.mydom" value="http://localhost:7452/dir/mysvc.asmx"/>
it went away again...sure to come back at any time...
UPDATE
If I explicitly add:
imports net.mydom
to the top of my code, the message goes away again (even though I was explicitly using the full net.mydom. when typing the variables.

WCF 'sub main' not found

I must be losing my mind...
After getting a test WCF hosted in a windows service, I'm trying for another one (practice, practice, practice).
I created a WCF service library, added one function. Then created a Windows Service, and added my WCF to the project. Did the rest of the stuff located here (http://joefreeman.co.uk/blog/2010/03/creating-a-setup-project-for-a-windows-wcf-service-with-visual-studio/)
Now I'm getting this "Sub Mian was not found in [WCF app]" error when I try to build the solution.
I didn't think WCF projects required a Sub Main as they are services and not applications. What am I doing wrong? I didn't have a sub main in my last project. Any ideas?
For others who are looking for the same answer I was...
Created a service in VB.NET (VS2010), and was getting the same error listed above...
'Sub Main' was not found in 'SERVICENAME.Service1'.
In VB.NET, VS2010 created a "Service1.Designer.vb" file for me automatically. Inside of that file was:
Shared Sub Main()
Dim ServicesToRun() As System.ServiceProcess.ServiceBase
' More than one NT Service may run within the same process. To add
' another service to this process, change the following line to
' create a second service object. For example,
'
' ServicesToRun = New System.ServiceProcess.ServiceBase () {New Service1, New MySecondUserService}
'
ServicesToRun = New System.ServiceProcess.ServiceBase() {New SERVICENAME}
System.ServiceProcess.ServiceBase.Run(ServicesToRun)
End Sub
To resolve this, right-click your solution name in the solution explorer, go to the "Application" tab, and pick "Sub Main" as your Startup object in the "Startup object" drop-down box. Recompile.
Granted, the file names and structure will be different in C#, but the idea is that Visual Studio put the Main procedure SOMEWHERE, and it hopefully should already know where it is.
The WCF service itself doesn't need a Sub Main, but your Windows Service does.
Compare against your previously built, working Windows Service.
edit: using C#, when I create a new project using the Windows Service template, I get the following initial code in a Program.cs file (static void Main is your Sub Main). I'd be very surprised if you don't also have this in your Windows Service.
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
static void Main()
Check you haven't accidentally changed the Application type to something stupid like "windows forms app", hit the properties of the project and make sure it's on "class library".

Silverlight client got NotFound error from WCF

There are a lot of article on this subject, but neither helped me. I am trying to implement service which could be used without "Add Service Ref..." mostly with advice from hhttp://www.netfxharmonics.com/2008/11/Understanding-WCF-Services-in-Silverlight-2 .
I made small project to reproduce problem.
http://hotfile.com/dl/96710945/9991ac3/SilverlightApplication8.zip.html
I tried solution like :
- Handling Faults in Silverlight
- Cross domain policy
etc
All standard checks are done like, service is active and reachable, client succeed to create channel etc.
I am stack whole week with this problem and I can not figure it out.
Every help is appreciate.
Denis,
try to create service in your web host project. Add service there and then you'll have a choice to add it as reference in your silverlight application. Just add a service in SilverlightApplication8.Web. Right click on SilverlightApplication8.Web --> Add new Item --> On left choose Silverlight --> Silverlight-enabled WCF service. And then add reference to your SilverlightApplication8.
I did not go in deeper investigation, but I assume that service implementation class type was not good.
So my factory class looked like:
Public Class TimeServiceFactory
Inherits System.ServiceModel.Activation.ServiceHostFactoryBase
Public Overrides Function CreateServiceHost(ByVal constructorString As String, ByVal baseAddresses() As System.Uri) As System.ServiceModel.ServiceHostBase
Dim host As New ServiceHost(constructorString, baseAddresses)
It needs to be changed in:
Public Class TimeServiceFactory
Inherits System.ServiceModel.Activation.ServiceHostFactoryBase
Public Overrides Function CreateServiceHost(ByVal constructorString As String, ByVal baseAddresses() As System.Uri) As System.ServiceModel.ServiceHostBase
Dim host As New ServiceHost(GetType(TimeService), baseAddresses)
Difference is I did not pass constructorString (which has information of type of service implementation class) , I passed GetType(TimeService) instate, which provided correct type information.

How do I properly set up a Silverlight-Enabled WCF Service?

EDIT: I started a closed vote on this question because I resolved the issue. I was doing everything fine, but a reference to an ASP URL rewriter that I downloaded and uninstalled a while ago still had a reference in IIS. This forum post by Waclaw Stypula (the one with the steps) helped me track this down, by accident. When I launched the run command, IIS told me that it (obviously) could not find the rewriter DLL. I removed the reference and the app ran fine after that.
I am following the silverlight.net tutorials by Jesse Liberty. Currently I am trying to do tutorial three, but I am running into a wall under the heading "CREATE THE WEB SERVICE" (about halfway down).
First, when I create the new service by adding it to the solution, the tutorial indicates that three files should be created; IService1.vb, Service1.svc, and Service1.svc.vb. I do not get the IService1.vb file when I add the service to the solution. I downloaded the copy of the project they provided, and the Service1.svc.vb file is in there, so I added one manually and copied the contents of the file. The tutorial says it is a VB tutorial, but displays C# in the accompanying screenshot so maybe that is the issue.
After I get all the files made up like the tutorials (copy/paste to make sure I don't have a typo), I try to add the service reference and get the following error:
The service class of type KeyboardControl_Web.Service1 both defines a ServiceContract and inherits a ServiceContract from type KeyboardControl_Web.IService1. Contract inheritance can only be used among interface types. If a class is marked with ServiceContractAttribute, it must be the only type in the hierarchy with ServiceContractAttribute. Consider moving the ServiceContractAttribute on type KeyboardControl_Web.IService1 to a separate interface that type KeyboardControl_Web.IService1 implements.
I tried googling different portions of the message, but did not find much useful information.
Here is the code for the different files:
//IService1.vb
Imports System.ServiceModel
' NOTE: If you change the class name "IService1" here, you must also update
' the reference to "IService1" in Web.config.
<ServiceContract()> _
Public Interface IService1
<OperationContract()> _
Function GetAllLocations() As List(Of Address)
End Interface
//Service1.svc.vb
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Runtime.Serialization
Imports System.ServiceModel
Imports System.Text
' NOTE: If you change the class name "Service1" here, you must also
' update the reference to "Service1" in Web.config and in the
' associated .svc file.
Public Class Service1
Implements IService1
Public Function GetAllLocations() As List(Of Address) Implements IService1.GetAllLocations
Dim db As New DataClasses1DataContext()
Dim matchingCustomers = From cust In db.userControlDemos Select cust
'Return matchingCustomers.ToList()
End Function
End Class
I am new to Silverlight/WCF in general, as well as to Interfaces and Services. Can you guys help me get on the right track?
EDIT: I should add that I am using Visual Studio 2008, on Windows Vista Business SP1.
if you have the Silverlight Tools for Visual Studio installed, instead of using the default WCF template, consider using the "Silverlight-enabled WCF Service" which simplifies things for you and puts all the required configuration in place. This new template was introduced in Beta 2 and still exist (ref: http://timheuer.com/blog/archive/2008/06/06/changes-to-accessing-services-in-silverlight-2-beta-2.aspx).